Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int row[8] = {0,1,2,3,4,5,6,7}; // 8x8 pins
- int col[8] = {8,9,10,11,12,13,A0,A1};
- int in[4] = {A2,A3,A4,A5};
- int y = 1; //player position
- int x = 1;
- // INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT
- int inPin = A2; // the number of the input pin
- int state = HIGH; // the current state of the output pin
- int reading; // the current reading from the input pin
- int previous = LOW; // the previous reading from the input pin
- // the follow variables are long's because the time, measured in miliseconds,
- // will quickly become a bigger number than can be stored in an int.
- long time = 0; // the last time the output pin was toggled
- long debounce = 200; // the debounce time, increase if the output flickers
- // INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT
- int grid[8][8] = {
- {1,1,1,1,1,1,1,1},
- {1,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,1},
- {1,1,1,1,1,1,1,1}
- };
- void setup() {
- for(int i=0;i<4;i++){
- pinMode(in[i],INPUT);
- }
- for(int i=0;i<8;i++){
- pinMode(row[i],OUTPUT);
- pinMode(col[i],OUTPUT);
- }
- }
- void loop() {
- reading = digitalRead(inPin);
- if (reading == HIGH && previous == LOW && millis() - time > debounce) {
- if (state == HIGH){
- state = LOW;
- y++;
- }
- else{
- state = HIGH;
- }
- time = millis();
- }
- previous = reading;
- // draw draw draw // draw draw draw // draw draw draw // draw draw draw // draw draw draw
- for(int i=0;i<8;i++){
- digitalWrite(row[i],HIGH);
- for(int j=0;j<8;j++){
- if(grid[i][j]){
- digitalWrite(col[j],LOW);
- }
- else if(i==y && j==x){
- digitalWrite(col[j],LOW);
- }
- else{
- digitalWrite(col[j],HIGH);
- }
- }
- delay(1);
- digitalWrite(row[i],LOW);
- }
- // draw draw draw // draw draw draw // draw draw draw // draw draw draw // draw draw draw // draw draw draw
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement