diff --git a/roulette/roulette.ino b/roulette/roulette.ino new file mode 100644 index 0000000..6d397bf --- /dev/null +++ b/roulette/roulette.ino @@ -0,0 +1,56 @@ +#define BUTTON 4 +int LED[] = {5, 6, 9, 10, 11}; +int val[5] = {255, 255, 0, 255, 255}; +int clk = 0; +#define DELAY 100 +#define STEP 100 +#define STOP 1000 +int delay_time = DELAY; +bool pressed = 0; +unsigned long checkpoint = 0; + +bool isPressed() { + static bool last = 1; + int result = 0; + if (last == 1 && digitalRead(BUTTON) == LOW) { + result = 1; + } + last = digitalRead(BUTTON); + delay(1); + return 0; +} + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + for (int i = 0; i < 5; i++) { + pinMode(LED[i], OUTPUT); + digitalWrite(LED[i], HIGH); + } + pinMode(BUTTON, INPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + if (isPressed()) { + pressed = !pressed; + if (!pressed) { + delay_time = DELAY; + } + Serial.println(pressed); + } + + if (millis() - checkpoint > delay_time) { + if (pressed) { + delay_time += STEP; + } + if (delay_time < STOP) { + for (int i = 0; i < 5; i++) { + analogWrite(LED[i], val[(i + clk) % 5]); + } + clk += 1; + } + + checkpoint = millis(); + } +}