This still has a bit of work left on it… I’m not totally convinced that the timing is even/smooth… it seems like the final LED in the loop is off in hit and release… though I’m not entirely if it’s my eyes or the code. Everything else is working well, I’m now able to adjust the sequence length via a potentiometer, pause the sequence using a push-button, and adjust sequence speed using another pot. The problem at this point remains having a button that first suspends the LED sequence, turns off any lit LEDs and then, when released, starts the sequence over again on the first frame. I’ve had a huge amount of help on the arduino forum and that’s been really whats made this go from nothing to something. Hopefully the code is done by the end of the weekend and I can begin to sort out how to board this out and design the interface.
const int buttonPin = 2;
const int ledPin = 12;
int buttonState = 0;
int leds[] = {3, 4, 5, 6, 7, 8, 9, 10};
#define NUMBER_OF_LEDS (sizeof(leds)/sizeof(int))
boolean flickbook[][NUMBER_OF_LEDS] = {
{ HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW},
{ LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW},
{ LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW},
{ LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW},
{ LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW},
{ LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW},
{ LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW},
{ LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH}
};
#define FRAMES (sizeof(flickbook)/(sizeof(flickbook[0])))
int sensorPin = 0;
const int sensorMin = 0;
const int sensorMax = 1023;
void setup() {
for (int led=0; led<NUMBER_OF_LEDS; led++) {
pinMode(leds[led], OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
}
void loop(){
int sensorReading1 = analogRead(2);
int range1 = map(sensorReading1, sensorMin, sensorMax, 0, 7);
switch (range1) {
case 0: {
long time = millis();
for (int frame=0; frame<1; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++){
digitalWrite(leds[led], flickbook[frame][led]);
}
(buttonState = digitalRead(buttonPin));
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, LOW);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() – time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}
break;
case 1: {
long time = millis();
for (int frame=0; frame<2; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++){
digitalWrite(leds[led], flickbook[frame][led]);
}
(buttonState = digitalRead(buttonPin));
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, LOW);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() – time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}
break;
case 2: {
long time = millis();
for (int frame=0; frame<3; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++){
digitalWrite(leds[led], flickbook[frame][led]);
}
(buttonState = digitalRead(buttonPin));
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, LOW);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() – time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}
break;
case 3: {
long time = millis();
for (int frame=0; frame<4; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++){
digitalWrite(leds[led], flickbook[frame][led]);
}
(buttonState = digitalRead(buttonPin));
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, LOW);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() – time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}
break;
case 4: {
long time = millis();
for (int frame=0; frame<5; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++){
digitalWrite(leds[led], flickbook[frame][led]);
}
(buttonState = digitalRead(buttonPin));
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, LOW);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() – time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}
break;
case 5: {
long time = millis();
for (int frame=0; frame<6; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++){
digitalWrite(leds[led], flickbook[frame][led]);
}
(buttonState = digitalRead(buttonPin));
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, LOW);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() – time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}
break;
case 6: {
long time = millis();
for (int frame=0; frame<7; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++){
digitalWrite(leds[led], flickbook[frame][led]);
}
(buttonState = digitalRead(buttonPin));
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, LOW);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() – time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}
break;
case 7: {
long time = millis();
for (int frame=0; frame<8; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++){
digitalWrite(leds[led], flickbook[frame][led]);
}
(buttonState = digitalRead(buttonPin));
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, LOW);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() – time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}
break;
}
}