Autoformatted

This commit is contained in:
Austen Adler 2016-06-03 16:11:37 -04:00
parent 274ac16155
commit 6834192f92

View File

@ -1,7 +1,5 @@
/*THE WORKING VERSION OF THE 4 BUTTON KEYBOARD /*THE WORKING VERSION OF THE 4 BUTTON KEYBOARD
LAYOUT LAYOUT
RedWire->| RedWire->|
| |
____________ ____________
@ -18,16 +16,12 @@ L1 = buttonState3, b4, v1, var + 5
L2 = buttonState1, b2, v3, var - 1 L2 = buttonState1, b2, v3, var - 1
L3 = buttonState, b1, v2, var + 1 L3 = buttonState, b1, v2, var + 1
L3 = buttonState2, b3, v4, var + 10 L3 = buttonState2, b3, v4, var + 10
*/ */
//Ints for counting multipress //Ints for counting multipress
int v1 = 0; int v1 = 0;
int v2 = 0; int v2 = 0;
int v3 = 0; int v3 = 0;
int v4 = 0; int v4 = 0;
//ints for button pins (only b1 - 4 are in use) //ints for button pins (only b1 - 4 are in use)
const int b1 = 2; const int b1 = 2;
const int b2 = 3; const int b2 = 3;
@ -35,14 +29,11 @@ const int b3 = 4;
const int b4 = 5; const int b4 = 5;
const int b5 = 6; const int b5 = 6;
const int b6 = 7; const int b6 = 7;
//int for counting number and submit //int for counting number and submit
int var = 0; int var = 0;
int subvar = 0; int subvar = 0;
//Not sure what this does, but don't want to delete it //Not sure what this does, but don't want to delete it
int ptrue = 0; int ptrue = 0;
//ints for counting button presses //ints for counting button presses
int buttonState = 0; int buttonState = 0;
int lastButtonState = 0; int lastButtonState = 0;
@ -52,7 +43,6 @@ int buttonState2 = 0;
int lastButtonState2 = 0; int lastButtonState2 = 0;
int buttonState3 = 0; int buttonState3 = 0;
int lastButtonState3 = 0; int lastButtonState3 = 0;
//ints for debouncing each button //ints for debouncing each button
long debounceDelay = 50; long debounceDelay = 50;
long lastDebounceTime = 0; long lastDebounceTime = 0;
@ -63,19 +53,15 @@ long lastDebounceTime2 = 0;
int state2 = 0; int state2 = 0;
long lastDebounceTime3 = 0; long lastDebounceTime3 = 0;
int state3 = 0; int state3 = 0;
/* the pins are set up as inputs and then set high, /* the pins are set up as inputs and then set high,
so that when the button is grounded it will notice it so that when the button is grounded it will notice it
and count it as a button press. this way, there are and count it as a button press. this way, there are
no resistors needed for the curcuit. no resistors needed for the curcuit.
The button should be connected from the pin, to the The button should be connected from the pin, to the
button, to ground, like this: button, to ground, like this:
PIN# --> Pin1 of button |--| -- Ground PIN# --> Pin1 of button |--| -- Ground
^ ^
Button | Button |
*/ */
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -93,11 +79,7 @@ void setup() {
digitalWrite(b5, HIGH); digitalWrite(b5, HIGH);
digitalWrite(b6, HIGH); digitalWrite(b6, HIGH);
} }
void loop() { void loop() {
state3 = digitalRead(b4); //read if grounded or not state3 = digitalRead(b4); //read if grounded or not
if ((millis() - lastDebounceTime3) > debounceDelay) { //if the button has not been pressed within debouncetime, do... if ((millis() - lastDebounceTime3) > debounceDelay) { //if the button has not been pressed within debouncetime, do...
buttonState3 = digitalRead(b4); buttonState3 = digitalRead(b4);
@ -113,7 +95,6 @@ void loop() {
} }
} }
} }
//the same goes for this //the same goes for this
state = digitalRead(b1); state = digitalRead(b1);
if ((millis() - lastDebounceTime) > debounceDelay) { if ((millis() - lastDebounceTime) > debounceDelay) {
@ -130,7 +111,6 @@ void loop() {
} }
} }
} }
//and this //and this
state1 = digitalRead(b2); state1 = digitalRead(b2);
if ((millis() - lastDebounceTime1) > debounceDelay) { if ((millis() - lastDebounceTime1) > debounceDelay) {
@ -147,7 +127,6 @@ void loop() {
} }
} }
} }
//... and this //... and this
state2 = digitalRead(b3); state2 = digitalRead(b3);
if ((millis() - lastDebounceTime2) > debounceDelay) { if ((millis() - lastDebounceTime2) > debounceDelay) {
@ -164,8 +143,6 @@ void loop() {
} }
} }
} }
// this whole section controls what letters correspond to what numbers, // this whole section controls what letters correspond to what numbers,
// and when to send the letter out // and when to send the letter out
if (var == 1) { //if the variable is 1, if (var == 1) { //if the variable is 1,
@ -175,9 +152,7 @@ void loop() {
var = 0; //reset the variable, so you can count to the next word. var = 0; //reset the variable, so you can count to the next word.
} }
} }
//the same goes for all the code below, untill the next comment. //the same goes for all the code below, untill the next comment.
if (var == 2) { if (var == 2) {
if (subvar == 1) { if (subvar == 1) {
Serial.print('B'); Serial.print('B');
@ -353,12 +328,8 @@ void loop() {
var = 0; var = 0;
} }
} }
// i know everything above could've been done with a map, but, i didn't do it like that. // i know everything above could've been done with a map, but, i didn't do it like that.
//this next code part control all the multipress. //this next code part control all the multipress.
if (v1 == 1) { //if one of the two buttons in the multipress section was pressed, if (v1 == 1) { //if one of the two buttons in the multipress section was pressed,
if (v3 == 1) { //and the second button in the multipress section was pressed, if (v3 == 1) { //and the second button in the multipress section was pressed,
subvar = 1; //do what you want that multipres section to do. In this case, it was subvar = 1; //do what you want that multipres section to do. In this case, it was
@ -371,10 +342,8 @@ void loop() {
var = var + 1; //the same here too var = var + 1; //the same here too
} }
} }
//the same goes for the below code, but with different buttons for //the same goes for the below code, but with different buttons for
//multipress, and different actions based on that //multipress, and different actions based on that
if (v2 == 1) { if (v2 == 1) {
if (v4 == 1) { if (v4 == 1) {
Serial.print(" "); Serial.print(" ");
@ -384,7 +353,6 @@ void loop() {
var = - 5; var = - 5;
} }
} }
if (v3 == 1) { if (v3 == 1) {
if (v4 == 1) { if (v4 == 1) {
Serial.println(""); Serial.println("");
@ -394,7 +362,6 @@ if (v3 == 1) {
var = var - 10; var = var - 10;
} }
} }
if (v1 == 1) { if (v1 == 1) {
if (v2 == 1) { if (v2 == 1) {
Serial.print("."); Serial.print(".");
@ -404,8 +371,6 @@ if (v1 == 1) {
var = var - 5; var = var - 5;
} }
} }
//reset the button states. not sure if i still need these, but dont want to risk deleting them. //reset the button states. not sure if i still need these, but dont want to risk deleting them.
// //
lastButtonState = buttonState; lastButtonState = buttonState;
@ -413,27 +378,3 @@ if (v1 == 1) {
lastButtonState2 = buttonState2; lastButtonState2 = buttonState2;
lastButtonState3 = buttonState3; lastButtonState3 = buttonState3;
} }