Created
June 19, 2014 19:29
-
-
Save hcwiley/b2a28c7e01c325de7487 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int row[8] = {7, 9, 6, 8, 2, 5, 3, 4}; | |
| int col[8] = {15, 10, 11, 13, 12, 14, 16, 17}; | |
| int accl_x = A5; | |
| // the setup routine runs once when you press reset: | |
| void setup() { | |
| // open a serial port | |
| Serial.begin(9600); | |
| pinMode(accl_x, INPUT); | |
| // initialize the row and column pins as outputs, set rows low, set columns high | |
| for (int i = 0; i < 8; i++) { | |
| pinMode (row[i], OUTPUT); | |
| digitalWrite(row[i], LOW); | |
| pinMode (col[i], OUTPUT); | |
| digitalWrite(col[i], HIGH); | |
| } | |
| // test all leds | |
| for (int r=0; r<8; r++) { | |
| if (r > 0) { | |
| digitalWrite(row[r-1], LOW); | |
| } | |
| else { | |
| digitalWrite(row[7], LOW); | |
| } | |
| digitalWrite(row[r], HIGH); | |
| for (int c = 0; c<8; c++) { | |
| if (c > 0) { | |
| digitalWrite(col[c-1], HIGH); | |
| } | |
| else { | |
| digitalWrite(col[7], HIGH); | |
| } | |
| digitalWrite(col[c], LOW); | |
| delay(20); | |
| } | |
| } | |
| } | |
| // the loop routine runs over and over again forever: | |
| void loop() { | |
| int x = analogRead(accl_x); | |
| int x_mapped = map(x, 267, 400, 0, 8); | |
| Serial.print(x); | |
| Serial.print(" => "); | |
| Serial.println(x_mapped); | |
| for (int r=0; r<8; r++) { | |
| digitalWrite(row[r], HIGH); | |
| for (int c = 0; c<8; c++) { | |
| if( c >= x_mapped ){ | |
| digitalWrite(col[c], LOW); | |
| } else { | |
| digitalWrite(col[c], HIGH); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment