Offline
Full Member
Karma: 1
Posts: 174
|
 |
« Reply #15 on: January 02, 2013, 12:18:32 am » |
That is much diffident then the one I have been going by;
Take a look
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #16 on: January 02, 2013, 12:26:32 am » |
Here's another thread worth reading on the 3 PWM question: hereCheers! Geoff
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 174
|
 |
« Reply #17 on: January 02, 2013, 12:39:31 am » |
I put the switch on pin 2 and the last LED on 3, but no go.
I am not liking this new hobby. When does it start to get fun.
I am using this project as part of a Night lite I am make, I planed on staring the carving tomorrow.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 10
Posts: 863
|
 |
« Reply #18 on: January 02, 2013, 12:47:57 am » |
There are only 2 PWM pins PIN 0 (5) and PIN 1 (6)
This is a common misconception. ATTiny85 has 4 pins capable of PWM, with two sharing the same clock source. I routinely use this little uC to run RGB LEDs. Sorry still stuck on this iPad or would post an example. Also, it is possible to drive any of the pins by software PWM if the application is lighting or anything else where accuracy or high frequencies aren't a requirement. Cheers! Geoff Really! if i had of known this 2 weeks ago, you'd have saved me about 30 bucks!  Which pins use PWM on the attiny85, i'll update my schematic - Thanks 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 174
|
 |
« Reply #19 on: January 02, 2013, 01:03:09 am » |
Geoff,
I moved the last LED off of pin 2 (7) and onto pin pin 4 (3). Works
Now I got to figure out the delay on the last set of instruction ( Flame look).
Let me know how it looks on yours.
Thanks.
PS. I have been stuck on this all Day. thanks for the heads up on the PWM pins.
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #20 on: January 02, 2013, 01:29:14 am » |
That's excellent news. Confirming the changes my side were removing the Serial.begin() and these pin assignments int switchPin = 3; // IC leg 2 (PB3) int led1Pin = 0; // IC leg 5 (PB0) int led2Pin = 1; // IC leg 6 (PB1) int led3Pin = 4; // IC leg 3 (PB4) Also, here's how it would look modified to use the internal pull-up resistor on the switch (as mentioned earlier). For this circuit you'd not have any additional resistors on the switch circuit, just wire to the switch and from there to ground. /* * Night Lite, final version */
int switchPin = 3; // IC leg 2 (PB3) int led1Pin = 0; // IC leg 5 (PB0) int led2Pin = 1; // IC leg 6 (PB1) int led3Pin = 4; // IC leg 3 (PB4)
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 digitalWrite(switchPin, HIGH); // set internal pull-up resistor pinMode(led1Pin, OUTPUT); pinMode(led2Pin, OUTPUT); pinMode(led3Pin, OUTPUT);
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));
} } }
Cheers ! Geoff
|
|
|
|
« Last Edit: January 02, 2013, 01:34:47 am by strykeroz »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 174
|
 |
« Reply #21 on: January 02, 2013, 01:31:34 am » |
When I removed the Serial.begin() that's when thing started to work. Can you explain why.
Again sorry, but this is how I learn.
Thanks.
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #22 on: January 02, 2013, 01:42:33 am » |
No need for any apology.
It's simply that Serial is a set of functions that talk to the RX and TX pins via the inbuilt UART on the ATMega. There is no hardware serial support on the ATTiny85 so that function cannot work.
There is a software serial available for the Arduino-Tiny library if I recall correctly so the functionality can be achieved another way if you need it.
Cheers ! Geoff
|
|
|
|
« Last Edit: January 02, 2013, 01:45:18 am by strykeroz »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 174
|
 |
« Reply #23 on: January 02, 2013, 02:00:59 am » |
Thanks to all your help, I got it working and leaned a lot in the process.
Now one more thing I would like to ask.
Because this is going to be a Night Lite I don't want to use batters. I don't know how log they would last.
That being said what would be the right size power supply.
Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #24 on: January 02, 2013, 02:38:18 am » |
Hi Glad to hear it's all working now your side. Depending on the particular ATTiny85 you're using there's a broad range of voltages which will be suitable. Operating Voltage – 1.8 - 5.5V for ATtiny25V/45V/85V – 2.7 - 5.5V for ATtiny25/45/85 Any wall wart in the 3 to 5 Volt range will be a safe bet (and somewhat cheap, if you don't have one laying about from an old mobile phone or similar to repurpose). Just remember if you use something lower than 5V you will need to adjust the size of the current limiting resistors you use for your LEDs down or they'll be dimmer (maybe not a bad thing for a night light, but best to test first). LEDcalc.com can help with the maths. All the best, Geoff
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 10
Posts: 863
|
 |
« Reply #25 on: January 02, 2013, 06:34:09 am » |
(PCINT5/RESET/ADC0/dW) PB5 (PCINT3/XTAL1/CLKI/OC1B/ADC3) PB3 (PCINT4/XTAL2/CLKO/OC1B/ADC2) PB4 GND VCC PB2 (SCK/USCK/SCL/ADC1/T0/INT0/PCINT2) PB1 (MISO/DO/AIN1/OC0B/OC1A/PCINT1) PB0 (MOSI/DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0)
pins 2,3,5,6 have PWM then!
Well wow! - 2 are high speed and the other 2 are not...
|
|
|
|
|
Logged
|
|
|
|
|
Denmark
Offline
God Member
Karma: 19
Posts: 674
|
 |
« Reply #26 on: January 02, 2013, 08:13:33 am » |
And two share the same pwm pin
So there are three different pwm pins:
PB4 PB0 PB1
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #27 on: January 02, 2013, 08:18:03 am » |
So there are three different pwm pins:
PB4 PB0 PB1
Yes, as I read it PB3 & PB4 are the inverted output of each other, so while they're both PWM they'll be the same as each other, only out of phase. This is a part of the datasheet that I get stuck in so I reserve the right to be wrong  Geoff
|
|
|
|
|
Logged
|
|
|
|
|
alabama
Offline
Full Member
Karma: 1
Posts: 168
|
 |
« Reply #28 on: January 02, 2013, 09:51:13 pm » |
Kculm The image I have shows pin 3 on leg two.
Leg 1 Reset Leg 2 PIN 3( Analog input 3) Leg 3 PIN 4( Analog input 2) Leg 4 GND Leg 5 PIN 0 (PWM) Leg 6 PIN 3 (PWM) Leg 7 PIN 2 (Analog Input 1) Leg 8 VCC My pinout cross reference lists Leg 6 as pin1, which has been working in my sketches. Am I missing something but how can leg2 and leg6 be pin3 in Arduino? TomJ
|
|
|
|
|
Logged
|
Einstein once said you don't really understand anything until you can explain it to your Grandmother
|
|
|
|
Brisbane, Australia
Offline
God Member
Karma: 17
Posts: 812
|
 |
« Reply #29 on: January 02, 2013, 10:31:39 pm » |
My pinout cross reference lists Leg 6 as pin1, which has been working in my sketches. Am I missing something but how can leg2 and leg6 be pin3 in Arduino? TomJ
Hi Tom You're not missing anything, the info he had was a bit incomplete/wrong initially, then he started using this: Cheers ! Geoff
|
|
|
|
|
Logged
|
|
|
|
|
|