Thank you for that. I was clearly up too late and should've gone to bed!
I've got the LED Flasher demo code merged with the switchCase example. There's something I don't get about how this library works...there doesn't seem to be any way to turn off the LEDs and then turn them back on. In the code below, case 0 causes all the LEDs to blink by updating them; case 1 shuts them off. However, when you switch from case 0 to case 1, some of the LEDs may stay lit, so I would like them to be off in case 1. The section of case 1 that's commented out doesn't work; instead, I added the digitalWrite commands for each LED to make sure they're off. When the code goes back to case 0 then the LEDs blink as expected.
// Merges LED Flasher with Switch Case demo, using a 5K pot
// Example of flashing multiple LEDs at different rates without delays
// Author: Nick Gammon
// Date: 23 December 2012
#include <LedFlasher.h>
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 800; // sensor maximum, discovered through experiment
// set up some LEDs
LedFlasher floodLight (8, 200, 300);
LedFlasher shuttleBayDoors (9, 300, 600);
LedFlasher impulseEngine (10, 900, 100);
LedFlasher strobe (11, 500, 1000);
LedFlasher navigation (12, 1000, 2000);
LedFlasher torpedoes (3, 250, 500);
void setup()
{
floodLight.begin ();
shuttleBayDoors.begin ();
impulseEngine.begin ();
strobe.begin ();
navigation.begin ();
torpedoes.begin ();
// initialize serial communication:
Serial.begin(9600);
} // end of setup
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
switch (range) {
case 0: // pot turned all the way off
Serial.println("case 0");
// update lights
floodLight.update ();
shuttleBayDoors.update ();
impulseEngine.update ();
strobe.update ();
navigation.update ();
torpedoes.update ();
break;
case 1: // pot turned about 1/4 way
Serial.println("case 1");
// floodLight.off ();
// shuttleBayDoors.off ();
// impulseEngine.off ();
// strobe.off ();
// navigation.off ();
// torpedoes.off ();
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(3, LOW);
break;
case 2: // pot turned about 1/2 of the way
Serial.println("case 2");
break;
case 3: // pot turned about 3/4 of the way
Serial.println("case 3");
break;
// do other useful stuff here ...
}
} // end of loop