I don't know if I should start a new topic but as this is related and might help the OP I'll stick it here.
I'm looking to do a similar thing to the OP and run an RGB LED from an ATtiny85, I have code that works on my UNO (but have changed the pin numbers) and have designed the circuit below for use with the ATtiny, I would test it but my ATtiny is on back order at the moment Have I done this right or do I need a bit of tinkering?
Schematic:
My code:
#include <EEPROM.h>
const int modePin = 2;
const int optionPin = 3;
const int redPin = 1;
const int greenPin = 4;
const int bluePin = 0;
byte red = 0;
byte green = 0;
byte blue = 0;
int modeEEPROM = 0;
int optionEEPROM = 1;
byte mode=0;
boolean modeState=0;
boolean lastModeState=0;
byte option=0;
boolean optionState=0;
boolean lastOptionState=0;
int wait=5;
int i=0;
int ledDelay = 50;
void setup()
{
Serial.begin(9600);
pinMode(modePin, INPUT);
pinMode(optionPin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
mode=EEPROM.read(modeEEPROM);
option=EEPROM.read(optionEEPROM);
}
void loop()
{
modeState = digitalRead(modePin);
if (modeState != lastModeState) {
if (modeState == HIGH) {
red=0;
green=0;
blue=0;
option=0;
i=0;
if(mode<7) {
mode++;
delay(250);
}
else {
mode=0;
}
EEPROM.write(modeEEPROM, mode);
EEPROM.write(optionEEPROM, option);
analogWrite(redPin, red); // Write current values to LED pins
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
}
lastModeState = modeState;
optionState = digitalRead(optionPin);
if (optionState != lastOptionState) {
if (optionState == HIGH) {
red=0;
green=0;
blue=0;
i=0;
option++;
EEPROM.write(optionEEPROM, option);
delay(250);
}
}
lastOptionState = optionState;
switch (mode)
{
case 0:
fullcolour();
break;
case 1:
redblue();
break;
case 2:
redgreenblue();
break;
case 3:
police();
break;
case 4:
strobe();
break;
case 5:
solid();
break;
case 6:
rainbow();
break;
case 7:
colourstrobe();
break;
}
Serial.print("mode = ");
Serial.println(mode);
Serial.print("option = ");
Serial.println(option);
}
There should be a 0.1 uF bypass / decoupling capacitor for the ATtiny85. When you build the circuit it should be physically as close as possible to the processor.
The 100 Ohm "control res" resistors are too small (more than 40mA can escape the Arduino pin), make them bigger, eg. 330 Ohm.
What's with all the "pull down" resistors? Use the internal pullups and put the switches between the pin and ground like you're supposed to (especially the RESET, which won't even work that way around).
sniffing1987:
I don't know if I should start a new topic but as this is related and might help the OP I'll stick it here.
New topic.[/quote]
Thanks for moving it
Thanks, always used the UNO so far so assumed (my dad always said never assume, it makes an ass out of you and me).
?? I'll look at google!
fungus:
The 100 Ohm "control res" resistors are too small (more than 40mA can escape the Arduino pin), make them bigger, eg. 330 Ohm.
What's with all the "pull down" resistors? Use the internal pullups and put the switches between the pin and ground like you're supposed to (especially the RESET, which won't even work that way around).
I never realised it had internal pull ups, changing it now
OC0A, OC0B, OC1B. All are output compare units. In fact there are 6 PWM output, but two pairs of them can only be complements of each other (OC1A and !OC1A, OC1B and !OC1B), and two pairs share the same physical pins (OC0A = !OC1A, OC0B = OC1A). So basically that leaves you with three usable ones and one complement one.
The cost implication is the only thing really stopping me, although I could change to 3AA's, change resistor values and do away with the voltage regulator entirely...
As advised on page one, just use 3 x AA batteries and no voltage regulator. The regulator is basically going to take the extra 1.5V and throw it away in the form of heat. It hardly seems worth it.