I need a little help.
I have written a simple little sketch involving 3 LED's and A Push Button.
It works fine on the Bread Board hooked up to the Arduino UNO. But when I put the code on a atTiny85 it wont run. I know I am programming the chip right. I have tested it with the Blink sketch.
I think it has something to do with the way I have it set up. I noticed pin 2 on the Arduino when sent as Analog input give out about 2 vdc, Pin 2(3) on the Tiny85 puts out 5. Not sure if I am on the right track with that. all so please keep in mind I am very new to all this, just over a week old.
Attached is my code and layout
Thanks
Code: Select all
/*
* Night Lite, final version
*/
int switchPin = 3; // switch is connected to pin 3 (pin 2 on Arduino)
int led1Pin = 0; // Blue LED on Pin 8 on Arduino
int led2Pin = 1; // Green LED on Pin 9 on Arduino
int led3Pin = 2; // Red LED on Pin 10 on Arduino
int val; // variable for reading the pin status
int val2; // variable for reading the delayed status
int buttonState; // variable to hold the button state
int lightMode = 0; // What mode is the light in?
void setup() {
pinMode(switchPin, INPUT); // Set the switch pin as input
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
Serial.begin(9600); // Set up serial communication at 9600bps
buttonState = digitalRead(switchPin); // read the initial state
}
void loop(){
val = digitalRead(switchPin); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(switchPin); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (lightMode == 0) { // if its off
lightMode = 1; // turn lights on!
}
else {
if (lightMode == 1) { // if its all-on
lightMode = 2; // make it blink!
}
else {
if (lightMode == 2) { // if its blinking
lightMode = 3; // make it wave!
}
else {
if (lightMode == 3) { // if its waving,
lightMode = 4;
}
else{
if (lightMode == 4){
lightMode =0;
} // turn light off!
}
}
}
}
}
buttonState = val; // save the new state in our variable
}
// Now do whatever the lightMode indicates
if (lightMode == 0) { // all-off
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, LOW);
}
if (lightMode == 1) { // Blue On
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, LOW);
}
if (lightMode == 2) { // Blue off, Green On
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, HIGH);
digitalWrite(led1Pin, LOW);
}
if (lightMode == 3) { // Red On Green Off
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, HIGH);
}
if (lightMode == 4) { // Flame
analogWrite(led1Pin, random(120)+135);
analogWrite(led2Pin, random(120)+135);
analogWrite(led3Pin, random(120)+135);
delay(random(100));
}
}
}