Advertisement
Guest User

Untitled

a guest
May 3rd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int row[8] = {0,1,2,3,4,5,6,7}; // 8x8 pins
  2. int col[8] = {8,9,10,11,12,13,A0,A1};
  3. int in[4] = {A2,A3,A4,A5};
  4.  
  5. int y = 1; //player position
  6. int x = 1;
  7.  
  8.  
  9. // INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT
  10.  
  11. int inPin = A2;         // the number of the input pin
  12.  
  13. int state = HIGH;      // the current state of the output pin
  14. int reading;           // the current reading from the input pin
  15. int previous = LOW;    // the previous reading from the input pin
  16.  
  17. // the follow variables are long's because the time, measured in miliseconds,
  18. // will quickly become a bigger number than can be stored in an int.
  19. long time = 0;         // the last time the output pin was toggled
  20. long debounce = 200;   // the debounce time, increase if the output flickers
  21.  
  22. // INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT INPUT
  23.  
  24. int grid[8][8] = {
  25.   {1,1,1,1,1,1,1,1},
  26.   {1,0,0,0,0,0,0,1},
  27.   {1,0,0,0,0,0,0,1},
  28.   {1,0,0,0,0,0,0,1},
  29.   {1,0,0,0,0,0,0,1},
  30.   {1,0,0,0,0,0,0,1},
  31.   {1,0,0,0,0,0,0,1},
  32.   {1,1,1,1,1,1,1,1}
  33. };
  34.  
  35. void setup() {  
  36.   for(int i=0;i<4;i++){
  37.     pinMode(in[i],INPUT);
  38.   }
  39.   for(int i=0;i<8;i++){
  40.     pinMode(row[i],OUTPUT);
  41.     pinMode(col[i],OUTPUT);
  42.   }
  43. }
  44.  
  45. void loop() {
  46.  
  47.   reading = digitalRead(inPin);
  48.  
  49.   if (reading == HIGH && previous == LOW && millis() - time > debounce) {
  50.     if (state == HIGH){
  51.       state = LOW;
  52.       y++;
  53.     }
  54.     else{
  55.       state = HIGH;
  56.     }
  57.  
  58.     time = millis();    
  59.   }
  60.  
  61.   previous = reading;
  62.  
  63.  
  64.   // draw draw draw // draw draw draw // draw draw draw // draw draw draw // draw draw draw
  65.   for(int i=0;i<8;i++){
  66.       digitalWrite(row[i],HIGH);
  67.       for(int j=0;j<8;j++){
  68.         if(grid[i][j]){
  69.           digitalWrite(col[j],LOW);
  70.         }
  71.         else if(i==y && j==x){
  72.           digitalWrite(col[j],LOW);
  73.         }
  74.         else{
  75.           digitalWrite(col[j],HIGH);
  76.         }
  77.       }
  78.       delay(1);
  79.       digitalWrite(row[i],LOW);
  80.   }
  81.  
  82.   // draw draw draw // draw draw draw // draw draw draw // draw draw draw // draw draw draw // draw draw draw
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement