SHARE
TWEET

do testu snake

a guest Aug 20th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int speed = 100;
  2. bool dosnake = false;
  3.  
  4. void setup() {
  5.   pinMode(4, OUTPUT); //lewa
  6.   pinMode(5, OUTPUT);
  7.   pinMode(6, OUTPUT);
  8.   pinMode(7, OUTPUT); //prawa
  9.  
  10.   pinMode(8, INPUT);
  11.   pinMode(9, INPUT); //fire button
  12.   pinMode(10, INPUT);
  13. }
  14.  
  15. void loop() {
  16.   while (dosnake == true) {
  17.     snake();
  18.     if (digitalRead(9) == HIGH) {
  19.       dosnake = false;
  20.     }
  21.     else if (digitalRead(10) == HIGH) {
  22.       if (millis()%50 == 0) {
  23.         speed -= 10;
  24.       }
  25.     }
  26.     else if (digitalRead(8) == HIGH) {
  27.       if (millis()%50 == 0) {
  28.         speed += 10;
  29.       }
  30.     }
  31.   }
  32.  
  33.   if (digitalRead(9) == HIGH and dosnake == false) {
  34.    dosnake = true;
  35.   }
  36. }
  37.  
  38. int snake() {
  39.     for(int i = 4; i < 8; i++) {
  40.       digitalWrite(i, HIGH);
  41.       delay(speed);
  42.     }
  43.     for(int j = 4; j < 8; j++) {
  44.       digitalWrite(j, LOW);
  45.       delay(speed);
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top