Archiving a bunch of old stuff

This commit is contained in:
Dan Buch
2015-06-22 13:15:42 -05:00
parent a6ec1d560e
commit bd1abd8734
395 changed files with 1 additions and 76 deletions

View File

@@ -0,0 +1,22 @@
const unsigned int LED_BIT0 = 10;
const unsigned int LED_BIT1 = 11;
const unsigned int LED_BIT2 = 12;
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);
randomSeed(analogRead(A0));
outputResult(random(1, 7));
}
void loop() {
}

View File

@@ -0,0 +1 @@
../../../arduino.mk

View 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;
}

View File

@@ -0,0 +1 @@
../../../arduino.mk

View File

@@ -0,0 +1,94 @@
// vim:filetype=arduino
#include <Bounce.h>
const unsigned int LED_BIT0 = 10;
const unsigned int LED_BIT1 = 11;
const unsigned int LED_BIT2 = 12;
const unsigned int START_BUTTON_PIN = 5;
const unsigned int GUESS_BUTTON_PIN = 7;
const unsigned int BAUD_RATE = 9600;
const unsigned int DEBOUNCE_DELAY = 20;
const unsigned int HOORAY_FLASHES = 10;
const unsigned int HOORAY_FLASH_BATCHES = 3;
const unsigned int HOORAY_FLASH_BATCH_PAUSE = 200;
const unsigned int HOORAY_FLASH_DURATION = 50;
Bounce startButton = Bounce();
Bounce guessButton = Bounce();
int guess = 0;
void outputResult(const long result) {
digitalWrite(LED_BIT0, result & B001);
digitalWrite(LED_BIT1, result & B010);
digitalWrite(LED_BIT2, result & B100);
}
void hooray() {
for (unsigned int i = 0; i < HOORAY_FLASH_BATCHES; i++) {
for (unsigned int i = 0; i < HOORAY_FLASHES; i++) {
outputResult(7);
delay(HOORAY_FLASH_DURATION);
outputResult(0);
delay(HOORAY_FLASH_DURATION);
}
delay(HOORAY_FLASH_BATCH_PAUSE);
}
}
void handleGuessButton() {
if (!guessButton.update()) {
return;
}
if (guessButton.read() == HIGH) {
guess = (guess % 6) + 1;
outputResult(guess);
Serial.print("Guess: ");
Serial.println(guess);
}
}
void handleStartButton() {
if (!startButton.update()) {
return;
}
if (startButton.read() == HIGH) {
const int result = random(1, 7);
outputResult(result);
Serial.print("Result: ");
Serial.println(result);
if (guess > 0) {
if (result == guess) {
Serial.println("You win!");
hooray();
} else {
Serial.println("You lose!");
}
}
delay(2000);
guess = 0;
}
}
void setup() {
pinMode(LED_BIT0, OUTPUT);
pinMode(LED_BIT1, OUTPUT);
pinMode(LED_BIT2, OUTPUT);
pinMode(START_BUTTON_PIN, INPUT);
pinMode(GUESS_BUTTON_PIN, INPUT);
randomSeed(analogRead(A0));
Serial.begin(BAUD_RATE);
startButton.attach(START_BUTTON_PIN);
startButton.interval(DEBOUNCE_DELAY);
guessButton.attach(GUESS_BUTTON_PIN);
guessButton.interval(DEBOUNCE_DELAY);
}
void loop() {
handleGuessButton();
handleStartButton();
}

View File

@@ -0,0 +1 @@
../../../arduino.mk

View 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;
}

View File

@@ -0,0 +1 @@
../../../arduino.mk

View File

@@ -0,0 +1 @@
../../../arduino.mk

View File

@@ -0,0 +1,27 @@
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);
}
oldButtonState = CURRENT_BUTTON_STATE;
}

View File

@@ -0,0 +1 @@
../../../arduino.mk

View File

@@ -0,0 +1,17 @@
const unsigned int BUTTON_PIN = 7;
const unsigned int LED_PIN = 13;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
}
void loop() {
const int BUTTON_STATE = digitalRead(BUTTON_PIN);
if (BUTTON_STATE == HIGH) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}

View File

@@ -0,0 +1 @@
../../../arduino.mk

View File

@@ -0,0 +1,21 @@
const unsigned int BUTTON_PIN = 7;
const unsigned int LED_PIN = 13;
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 == HIGH) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(LED_PIN, ledState);
}