I'm trying to write some code that will allow me to selectively activate/deactivate portions of a loop using the "simple RF L4 receiver" and an Arduino Uno R3. My goal is to have four different effects for an LPD8806 strip, each triggered by a button on the four button key fob. The D0, D1, D2, D3 pins on the L4 are connected to the A0, A1, A2, A3 pins on the Uno.
I think that what is required is a statement along the lines of "when pin A0 is HIGH, execute one part of the loop (effect), and ignore all of the rest"
I initially tried to do this using an "if" statement, but couldn't get it quite right (I posted on that a while back, thanks again to those who helped). Over the weekend I tinkered around with a switch/case statement without any success.
I have now exhausted the thimbleful of knowledge that I have (easily done), and could use an assist to get me over the hump! Am I on the right track, or is there a much better way to do this?
Thanks friends!
Code: Select all
#include "LPD8806.h"
#include "SPI.h"
LPD8806 strip = LPD8806(50);
const int switchPinA = A0;
const int switchPinB = A1;
const int switchPinC = A2;
const int switchPinD = A3;
int sensorValueA = 0;
int sensorValueB = 0;
int sensorValueC = 0;
int sensorValueD = 0;
void setup() {
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
pinMode(switchPinA, INPUT);
pinMode(switchPinB, INPUT);
pinMode(switchPinC, INPUT);
pinMode(switchPinD, INPUT);
}
// function prototypes, do not remove these!
void colorChase(uint32_t c, uint8_t wait);
void colorWipe(uint32_t c, uint8_t wait);
void dither(uint32_t c, uint8_t wait);
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
void wave(uint32_t c, int cycles, uint8_t wait);
void rainbowCycle(uint8_t wait);
uint32_t Wheel(uint16_t WheelPos);
void loop() {
sensorValueA = analogRead(switchPinA);
sensorValueB = analogRead(switchPinB);
sensorValueC = analogRead(switchPinC);
sensorValueD = analogRead(switchPinD);
int range = (sensorValueA, sensorValueB, sensorValueC, sensorValueD);
switch (range) {
case 1: (analogRead(switchPinA) == HIGH);
// Fill the entire strip with...
colorWipe(strip.Color(127,1,25), 10); //pink
// Clear strip data before start of next effect
for (int i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0);
}
break;
case 2: (analogRead(switchPinB) == HIGH);
// Fill the entire strip with...
colorWipe(strip.Color(127,18,0), 10); //orangered
// Clear strip data before start of next effect
for (int i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0);
}
break;
case 3: (analogRead(switchPinC) == HIGH);
colorWipe(strip.Color(127, 0, 127), 10); //magenta
// Clear strip data before start of next effect
for (int i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0);
}
break;
case 4: (analogRead(switchPinD) == HIGH);
colorWipe(strip.Color(0,0,127), 10); // blue
// Clear strip data before start of next effect
for (int i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 0);
}
break;
}
}
void colorWipe(uint32_t c, uint8_t wait) {
int i;
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}