Archiving a bunch of old stuff
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
export ARDUINODIR=/usr/share/arduino
|
||||
export BOARD=uno
|
||||
|
||||
export ARTISTIC_STYLE_OPTIONS='--style=attach -s4'
|
@@ -1,21 +0,0 @@
|
||||
EVERYTHING := \
|
||||
arduino.mk \
|
||||
libraries/Bounce/Bounce.h
|
||||
|
||||
.PHONY: all
|
||||
all: $(EVERYTHING)
|
||||
|
||||
.PHONY: all
|
||||
style:
|
||||
astyle -r '*.ino' -n
|
||||
|
||||
arduino.mk:
|
||||
curl -L -o $@ -s http://ed.am/dev/make/arduino-mk/arduino.mk
|
||||
|
||||
libraries/Bounce/Bounce.h: libraries/.raw/Bounce-Arduino-Wiring/Bounce
|
||||
ln -svf $(PWD)/libraries/.raw/Bounce-Arduino-Wiring/Bounce $(PWD)/libraries/Bounce
|
||||
|
||||
libraries/.raw/Bounce-Arduino-Wiring/Bounce:
|
||||
mkdir -p libraries/.raw/Bounce-Arduino-Wiring && \
|
||||
curl -L -s https://github.com/thomasfredericks/Bounce-Arduino-Wiring/archive/8c6fb3b3437b66215c579d23b716916c9b65881b.tar.gz | \
|
||||
tar xzf - -C libraries/.raw/Bounce-Arduino-Wiring --strip-components=1
|
@@ -1,63 +0,0 @@
|
||||
const unsigned int LED_PIN = 13;
|
||||
const unsigned int NOTE_MULTIPLIER = 100;
|
||||
|
||||
const unsigned int QUARTER_NOTE = 8;
|
||||
const unsigned int EIGHTH_NOTE = 4;
|
||||
const unsigned int SIXTEENTH_NOTE = 2;
|
||||
const unsigned int THIRTYSECOND_NOTE = 1;
|
||||
|
||||
int measure0[] = {-8, -8, -8, 2, 2, 2, 2, 0};
|
||||
int measure1[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure2[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure3[] = {4, 4, 4, 4, 4, 4, 4, 4, 0};
|
||||
int measure4[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure5[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure6[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure7[] = {4, 4, 4, 4, 4, 4, 4, 4, 0};
|
||||
int measure8[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
|
||||
int measurePop[] = {4, -4, -8, -8, -8, 0};
|
||||
|
||||
void playNote(int note) {
|
||||
if (note > 0) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
delay((NOTE_MULTIPLIER * note) / 2);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
delay((NOTE_MULTIPLIER * note) / 2);
|
||||
} else if (note < 0) {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
delay(NOTE_MULTIPLIER * (-1 * note));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void playMeasure(int measure[]) {
|
||||
for (int i = 0;; i++) {
|
||||
int note = measure[i];
|
||||
if (note == 0) {
|
||||
return;
|
||||
}
|
||||
playNote(note);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// int testMeasure[] = {2, 2, 2, 2, 2, -2, -2, -2, 0};
|
||||
// playMeasure(testMeasure);
|
||||
playMeasure(measure0);
|
||||
playMeasure(measure1);
|
||||
playMeasure(measure2);
|
||||
playMeasure(measure3);
|
||||
playMeasure(measure4);
|
||||
playMeasure(measure5);
|
||||
playMeasure(measure6);
|
||||
playMeasure(measure7);
|
||||
playMeasure(measure8);
|
||||
playMeasure(measurePop);
|
||||
}
|
@@ -1 +0,0 @@
|
||||
../../arduino.mk
|
@@ -1 +0,0 @@
|
||||
../../arduino.mk
|
@@ -1,28 +0,0 @@
|
||||
const unsigned int BAUD_RATE = 9600;
|
||||
unsigned int keys = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(BAUD_RATE);
|
||||
Serial.print("> ");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.write(Serial.read());
|
||||
keys++;
|
||||
|
||||
if (keys == 100) {
|
||||
Serial.println("\nKABOOM!!!");
|
||||
keys = 0;
|
||||
Serial.print("> ");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.print(keys);
|
||||
Serial.println(" keys pressed");
|
||||
Serial.print("> ");
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
const unsigned int LED_PIN = 13;
|
||||
const unsigned int PAUSE = 700;
|
||||
const unsigned int FLASH_DURATION = 100;
|
||||
|
||||
|
||||
void flash(int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
delay(FLASH_DURATION);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
delay(FLASH_DURATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
for (int i = 1; i < 4; i++) {
|
||||
flash(i);
|
||||
delay(PAUSE);
|
||||
}
|
||||
delay(PAUSE);
|
||||
}
|
@@ -1 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,54 +0,0 @@
|
||||
const unsigned int LED_PIN = 13;
|
||||
const unsigned int BAUD_RATE = 9600;
|
||||
|
||||
void ledOn() {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
Serial.println("LED on");
|
||||
}
|
||||
|
||||
void ledOff() {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
Serial.println("LED off");
|
||||
}
|
||||
|
||||
void ledBlink() {
|
||||
Serial.println("BLINKY TIME");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ledOn();
|
||||
delay(100);
|
||||
ledOff();
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void handleInput() {
|
||||
int c = Serial.read();
|
||||
|
||||
switch (c) {
|
||||
case '1':
|
||||
ledOn();
|
||||
break;
|
||||
case '2':
|
||||
ledOff();
|
||||
break;
|
||||
case '3':
|
||||
ledBlink();
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown command: ");
|
||||
Serial.println(c);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
Serial.begin(BAUD_RATE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
handleInput();
|
||||
}
|
@@ -1 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,22 +0,0 @@
|
||||
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() {
|
||||
}
|
@@ -1 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,28 +0,0 @@
|
||||
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 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,94 +0,0 @@
|
||||
// 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();
|
||||
}
|
@@ -1 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,32 +0,0 @@
|
||||
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 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,27 +0,0 @@
|
||||
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;
|
||||
}
|
@@ -1 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,21 +0,0 @@
|
||||
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);
|
||||
}
|
@@ -1 +0,0 @@
|
||||
../../../arduino.mk
|
@@ -1,5 +0,0 @@
|
||||
void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
// vim:filetype=arduino
|
||||
#include <ctype.h>
|
||||
#include <Arduino.h>
|
||||
#include "telegraph.h"
|
||||
|
||||
const char* LETTERS[] = {
|
||||
".-", // A
|
||||
"-...", // B
|
||||
"-.-.", // C
|
||||
"-..", // D
|
||||
".", // E
|
||||
"..-.", // F
|
||||
"--.", // G
|
||||
"....", // H
|
||||
"..", // I
|
||||
".---", // J
|
||||
"-.-", // K
|
||||
".-..", // L
|
||||
"--", // M
|
||||
"-.", // N
|
||||
"---", // O
|
||||
".--.", // P
|
||||
"--.-", // Q
|
||||
".-.", // R
|
||||
"...", // S
|
||||
"-", // T
|
||||
"..-", // U
|
||||
"...-", // V
|
||||
".--", // W
|
||||
"-..-", // X
|
||||
"-.--", // Y
|
||||
"--.." // Z
|
||||
};
|
||||
|
||||
const char* DIGITS[] = {
|
||||
"-----", // 0
|
||||
".----", // 1
|
||||
"..---", // 2
|
||||
"...--", // 3
|
||||
"....-", // 4
|
||||
".....", // 5
|
||||
"-....", // 6
|
||||
"--...", // 7
|
||||
"---..", // 8
|
||||
"----.", // 9
|
||||
};
|
||||
|
||||
Telegraph::Telegraph(const int output_pin, const int dit_length) {
|
||||
_output_pin = output_pin;
|
||||
_dit_length = dit_length;
|
||||
_dah_length = dit_length * 3;
|
||||
pinMode(_output_pin, OUTPUT);
|
||||
}
|
||||
|
||||
void Telegraph::output_code(const char* code) {
|
||||
const unsigned int code_length = strlen(code);
|
||||
|
||||
for (unsigned int i = 0; i < code_length; i++) {
|
||||
if (code[i] == '.') {
|
||||
dit();
|
||||
} else {
|
||||
dah();
|
||||
}
|
||||
|
||||
if (i != code_length - 1) {
|
||||
delay(_dit_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Telegraph::dit() {
|
||||
Serial.print(".");
|
||||
output_symbol(_dit_length);
|
||||
}
|
||||
|
||||
void Telegraph::dah() {
|
||||
Serial.print("-");
|
||||
output_symbol(_dah_length);
|
||||
}
|
||||
|
||||
void Telegraph::output_symbol(const int length) {
|
||||
digitalWrite(_output_pin, HIGH);
|
||||
delay(length);
|
||||
digitalWrite(_output_pin, LOW);
|
||||
}
|
||||
|
||||
void Telegraph::send_message(const char* message) {
|
||||
unsigned int message_length = (unsigned int)strlen(message);
|
||||
for (unsigned int i = 0; i < message_length; i++) {
|
||||
const char current_char = toupper(message[i]);
|
||||
|
||||
if (isalpha(current_char)) {
|
||||
output_code(LETTERS[current_char - 'A']);
|
||||
delay(_dah_length);
|
||||
} else if (isdigit(current_char)) {
|
||||
output_code(DIGITS[current_char - '0']);
|
||||
delay(_dah_length);
|
||||
} else if (current_char == ' ') {
|
||||
Serial.print(" ");
|
||||
delay(_dit_length * 7);
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
#ifndef __TELEGRAPH_H__
|
||||
#define __TELEGRAPH_H__
|
||||
|
||||
class Telegraph {
|
||||
public:
|
||||
Telegraph(const int output_pin, const int dit_length);
|
||||
void send_message(const char* message);
|
||||
private:
|
||||
void dit();
|
||||
void dah();
|
||||
void output_code(const char* code);
|
||||
void output_symbol(const int length);
|
||||
|
||||
int _output_pin;
|
||||
int _dit_length;
|
||||
int _dah_length;
|
||||
};
|
||||
#endif
|
Reference in New Issue
Block a user