Adding debounce button thingy and dice + button version
This commit is contained in:
parent
244a3ee1a9
commit
af850b2d91
28
arduino/DebounceButton/DebounceButton.ino
Normal file
28
arduino/DebounceButton/DebounceButton.ino
Normal file
@ -0,0 +1,28 @@
|
||||
const unsigned int BUTTON_PIN = 7;
|
||||
const unsigned int LED_PIN = 13;
|
||||
|
||||
int oldButtonState = LOW;
|
||||
int ledState = LOW;
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
const int CURRENT_BUTTON_STATE = digitalRead(BUTTON_PIN);
|
||||
|
||||
if (CURRENT_BUTTON_STATE != oldButtonState &&
|
||||
CURRENT_BUTTON_STATE == HIGH) {
|
||||
if (ledState == LOW) {
|
||||
ledState = HIGH;
|
||||
} else {
|
||||
ledState = LOW;
|
||||
}
|
||||
|
||||
digitalWrite(LED_PIN, ledState);
|
||||
delay(50);
|
||||
}
|
||||
|
||||
oldButtonState = CURRENT_BUTTON_STATE;
|
||||
}
|
1
arduino/DebounceButton/Makefile
Symbolic link
1
arduino/DebounceButton/Makefile
Symbolic link
@ -0,0 +1 @@
|
||||
../arduino.mk
|
32
arduino/DiceWithButton/DiceWithButton.ino
Normal file
32
arduino/DiceWithButton/DiceWithButton.ino
Normal file
@ -0,0 +1,32 @@
|
||||
const unsigned int LED_BIT0 = 10;
|
||||
const unsigned int LED_BIT1 = 11;
|
||||
const unsigned int LED_BIT2 = 12;
|
||||
const unsigned int BUTTON_PIN = 7;
|
||||
|
||||
int currentValue = 0;
|
||||
int oldValue = 0;
|
||||
|
||||
void outputResult(const long result) {
|
||||
digitalWrite(LED_BIT0, result & B001);
|
||||
digitalWrite(LED_BIT1, result & B010);
|
||||
digitalWrite(LED_BIT2, result & B100);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BIT0, OUTPUT);
|
||||
pinMode(LED_BIT1, OUTPUT);
|
||||
pinMode(LED_BIT2, OUTPUT);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
randomSeed(analogRead(A0));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
currentValue = digitalRead(BUTTON_PIN);
|
||||
|
||||
if (currentValue != oldValue && currentValue == HIGH) {
|
||||
outputResult(random(1, 7));
|
||||
delay(50);
|
||||
}
|
||||
|
||||
oldValue = currentValue;
|
||||
}
|
1
arduino/DiceWithButton/Makefile
Symbolic link
1
arduino/DiceWithButton/Makefile
Symbolic link
@ -0,0 +1 @@
|
||||
../arduino.mk
|
Loading…
Reference in New Issue
Block a user