Autoformatted
This commit is contained in:
parent
274ac16155
commit
6834192f92
@ -1,33 +1,27 @@
|
||||
/*THE WORKING VERSION OF THE 4 BUTTON KEYBOARD
|
||||
|
||||
LAYOUT
|
||||
|
||||
RedWire->|
|
||||
|
|
||||
____________
|
||||
| L1 L2 |
|
||||
| |
|
||||
| |
|
||||
| L3 L4 |
|
||||
| |
|
||||
------------
|
||||
| |
|
||||
| |
|
||||
----
|
||||
L1 = buttonState3, b4, v1, var + 5
|
||||
L2 = buttonState1, b2, v3, var - 1
|
||||
L3 = buttonState, b1, v2, var + 1
|
||||
L3 = buttonState2, b3, v4, var + 10
|
||||
|
||||
|
||||
*/
|
||||
|
||||
LAYOUT
|
||||
RedWire->|
|
||||
|
|
||||
____________
|
||||
| L1 L2 |
|
||||
| |
|
||||
| |
|
||||
| L3 L4 |
|
||||
| |
|
||||
------------
|
||||
| |
|
||||
| |
|
||||
----
|
||||
L1 = buttonState3, b4, v1, var + 5
|
||||
L2 = buttonState1, b2, v3, var - 1
|
||||
L3 = buttonState, b1, v2, var + 1
|
||||
L3 = buttonState2, b3, v4, var + 10
|
||||
*/
|
||||
//Ints for counting multipress
|
||||
int v1 = 0;
|
||||
int v2 = 0;
|
||||
int v3 = 0;
|
||||
int v4 = 0;
|
||||
|
||||
//ints for button pins (only b1 - 4 are in use)
|
||||
const int b1 = 2;
|
||||
const int b2 = 3;
|
||||
@ -35,14 +29,11 @@ const int b3 = 4;
|
||||
const int b4 = 5;
|
||||
const int b5 = 6;
|
||||
const int b6 = 7;
|
||||
|
||||
//int for counting number and submit
|
||||
int var = 0;
|
||||
int subvar = 0;
|
||||
|
||||
//Not sure what this does, but don't want to delete it
|
||||
int ptrue = 0;
|
||||
|
||||
//ints for counting button presses
|
||||
int buttonState = 0;
|
||||
int lastButtonState = 0;
|
||||
@ -52,7 +43,6 @@ int buttonState2 = 0;
|
||||
int lastButtonState2 = 0;
|
||||
int buttonState3 = 0;
|
||||
int lastButtonState3 = 0;
|
||||
|
||||
//ints for debouncing each button
|
||||
long debounceDelay = 50;
|
||||
long lastDebounceTime = 0;
|
||||
@ -63,20 +53,16 @@ long lastDebounceTime2 = 0;
|
||||
int state2 = 0;
|
||||
long lastDebounceTime3 = 0;
|
||||
int state3 = 0;
|
||||
|
||||
/* the pins are set up as inputs and then set high,
|
||||
so that when the button is grounded it will notice it
|
||||
and count it as a button press. this way, there are
|
||||
no resistors needed for the curcuit.
|
||||
|
||||
The button should be connected from the pin, to the
|
||||
button, to ground, like this:
|
||||
|
||||
PIN# --> Pin1 of button |--| -- Ground
|
||||
^
|
||||
Button |
|
||||
|
||||
*/
|
||||
so that when the button is grounded it will notice it
|
||||
and count it as a button press. this way, there are
|
||||
no resistors needed for the curcuit.
|
||||
The button should be connected from the pin, to the
|
||||
button, to ground, like this:
|
||||
PIN# --> Pin1 of button |--| -- Ground
|
||||
^
|
||||
Button |
|
||||
*/
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("Begin Typing");
|
||||
@ -93,11 +79,7 @@ void setup() {
|
||||
digitalWrite(b5, HIGH);
|
||||
digitalWrite(b6, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
|
||||
state3 = digitalRead(b4); //read if grounded or not
|
||||
if ((millis() - lastDebounceTime3) > debounceDelay) { //if the button has not been pressed within debouncetime, do...
|
||||
buttonState3 = digitalRead(b4);
|
||||
@ -113,7 +95,6 @@ void loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//the same goes for this
|
||||
state = digitalRead(b1);
|
||||
if ((millis() - lastDebounceTime) > debounceDelay) {
|
||||
@ -130,7 +111,6 @@ void loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//and this
|
||||
state1 = digitalRead(b2);
|
||||
if ((millis() - lastDebounceTime1) > debounceDelay) {
|
||||
@ -147,7 +127,6 @@ void loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//... and this
|
||||
state2 = digitalRead(b3);
|
||||
if ((millis() - lastDebounceTime2) > debounceDelay) {
|
||||
@ -164,10 +143,8 @@ void loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// this whole section controls what letters correspond to what numbers,
|
||||
// and when to send the letter out
|
||||
// this whole section controls what letters correspond to what numbers,
|
||||
// and when to send the letter out
|
||||
if (var == 1) { //if the variable is 1,
|
||||
if (subvar == 1) { //and, if you pressed the submit button,
|
||||
Serial.print('A'); //print the letter 'A' (A is the first letter in the alphabet)
|
||||
@ -175,9 +152,7 @@ void loop() {
|
||||
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 (subvar == 1) {
|
||||
Serial.print('B');
|
||||
@ -353,12 +328,8 @@ void loop() {
|
||||
var = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
|
||||
// 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.
|
||||
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,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
//the same goes for the below code, but with different buttons for
|
||||
//multipress, and different actions based on that
|
||||
|
||||
if (v2 == 1) {
|
||||
if (v4 == 1) {
|
||||
Serial.print(" ");
|
||||
@ -384,8 +353,7 @@ void loop() {
|
||||
var = - 5;
|
||||
}
|
||||
}
|
||||
|
||||
if (v3 == 1) {
|
||||
if (v3 == 1) {
|
||||
if (v4 == 1) {
|
||||
Serial.println("");
|
||||
v3 = 0;
|
||||
@ -394,8 +362,7 @@ if (v3 == 1) {
|
||||
var = var - 10;
|
||||
}
|
||||
}
|
||||
|
||||
if (v1 == 1) {
|
||||
if (v1 == 1) {
|
||||
if (v2 == 1) {
|
||||
Serial.print(".");
|
||||
v1 = 0;
|
||||
@ -404,8 +371,6 @@ if (v1 == 1) {
|
||||
var = var - 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//reset the button states. not sure if i still need these, but dont want to risk deleting them.
|
||||
//
|
||||
lastButtonState = buttonState;
|
||||
@ -413,27 +378,3 @@ if (v1 == 1) {
|
||||
lastButtonState2 = buttonState2;
|
||||
lastButtonState3 = buttonState3;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user