Created
June 19, 2014 20:07
-
-
Save hcwiley/2f0dfccf3351c102b08a to your computer and use it in GitHub Desktop.
This file contains 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; | |
int accl_y = A4; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// open a serial port | |
Serial.begin(9600); | |
pinMode(accl_x, INPUT); | |
pinMode(accl_y, 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); | |
int y = analogRead(accl_y); | |
int y_mapped = map(y, 267, 400, 0, 8); | |
Serial.print("x: "); | |
Serial.print(x); | |
Serial.print(" => "); | |
Serial.println(x_mapped); | |
Serial.print("y: "); | |
Serial.print(y); | |
Serial.print(" => "); | |
Serial.println(y_mapped); | |
Serial.println(); | |
for (int r=0; r<8; r++) { | |
digitalWrite(row[r], LOW); | |
for (int c = 0; c<8; c++) { | |
digitalWrite(col[c], HIGH); | |
} | |
} | |
digitalWrite(col[7-x_mapped], LOW); | |
if ( 7-x_mapped+1 < 8 ) | |
digitalWrite(col[7-x_mapped+1], LOW); | |
digitalWrite(row[y_mapped], HIGH); | |
if ( y_mapped+1 < 8 ) | |
digitalWrite(row[y_mapped+1], HIGH); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment