俄羅斯輸盤
This commit is contained in:
56
roulette/roulette.ino
Normal file
56
roulette/roulette.ino
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user