Sorry to post again… should’ve asked in my earlier post but didn’t even think about it.
Can anyone explain to me why you would use two separate resistors, before and after the LED? (Other than just not having the right value)
Isn’t that basically setting up a “Voltage Divider” ?
Using just the 380 ohm to Ground would work fine.
And actually last night, I got some Samples from MARL (woot), 6 Dual Color LEDs on a PCB 2x3 mount. Hooked up the top 3 and kind of used the HIGH and LOW idea, worked out well, but I can only assume there’s a better way to code it…
How it’s set up, the positive of each of the colors is setup respectively.
So if pinRed[2], HIGH, then pinGreen[3], LOW will turn on the first LED in Red. pinGreen[3], HIGH and pinRed[2], LOW will turn the LED red.
What it’s doing is reading a potentiometer in 4 ranges. Each range will do a variety of blinking. (as you can tell from the code)
This is my first time actually hand writing a code without needing much information, so I’m proud! (Insight welcome, and appreciated!)
int pinRed[] = {2,4,6};
int pinGreen[] = {3,5,7};
int potPin = 0;
int count = 0;
const int sensorMin = 0;
const int sensorMax = 1024;
void setup(){
for (count=0;count<5;count++) {
pinMode(pinRed[count], OUTPUT);
pinMode(pinGreen[count], OUTPUT);
}
}
void loop(){
int val = analogRead(0);
int range = map(val, sensorMin, sensorMax, 0, 3);
switch (range) {
case 0:
fullRed();
delay(750);
allOff();
delay(750);
break;
case 1:
fullRed();
delay(750);
fullGreen();
delay(750);
break;
case 2:
fullGreen();
delay(750);
allOff();
delay(750);
break;
case 3:
blinkage;
break;
}
}
void fullRed(){
int i;
for (i=0;i<3;i=i+1){
digitalWrite(pinGreen[i], HIGH);
digitalWrite(pinRed[i], LOW);
}
}
void fullGreen(){
int i;
for (i=0;i<3;i=i+1){
digitalWrite(pinRed[i], HIGH);
digitalWrite(pinGreen[i], LOW);
}
}
void allOff(){
int i;
for (i=0; i<3; i = i++){
digitalWrite(pinRed[i], LOW);
digitalWrite(pinGreen[i], LOW);
}
}
void blinkage(){
int i;
for (i=0; i<3; i = i++){
digitalWrite(pinRed[random(i)], HIGH);
digitalWrite(pinGreen[random(i)], LOW);
}
}