I have been using the Arduino Uno R3 for a project I'm building, and I read where you can migrate it all onto an ATTiny85. I picked up a few ATTiny85 20PU chips off of ebay. I tried to move my code to one, after building a shield, but the timing was messed up. So, I adjusted the timing and it seems to work, but now I think my millis are off.. After more research, I read that it might have something to do with millis rollover.
No...
didn't try that. I will do it now and see what happens.
Quick update.. Tried it out. Fixed my timing issue, but, the code is still not working.
For the first 5 minutes or so, everything works correctly, then after that, it completely ignores the "millis() - beenpressedsince > 300 " portion of the code and just fires off the "DoTheThing()" command.
TinyUser:
No...
didn't try that. I will do it now and see what happens.
Quick update.. Tried it out. Fixed my timing issue, but, the code is still not working.
For the first 5 minutes or so, everything works correctly, then after that, it completely ignores the "millis() - beenpressedsince > 300 " portion of the code and just fires off the "DoTheThing()" command.
It's impossible to help without seeing ALL the code
I totally agree with you on that one, fungus, that's why i'm asking for pointers. Even if I gave you all the code it would be worthless unless you could see the all of the code behind the AVR.
This is why i'm asking for direction instead of the solution.
const int switchpin = 1; // pin 6
const int pwmPin = 0;// pin 5
const int indPin = 2; // secondary indicator pin to let me know it fired
const int nobeam = 0; // pwmled off
const int lowbeam = 16; //pwmled dim
const int highbeam = 255; // pwmled full on
int ledVal = 16;
int reading = 0;
int msdelay = 400;
int lastDebounceTime;
int hasBlinked;
int lastBlink;
int lightStatus;
void setup() {
// initialize the digital pin as an output.
pinMode(pwmPin, OUTPUT);
pinMode(switchpin, INPUT);
pinMode(indPin, OUTPUT);
digitalWrite(indPin, HIGH);
analogWrite(pwmPin, ledVal);
}
// the loop routine runs over and over again forever:
void loop() {
//
//
// set the LED:
void Blink(){
digitalWrite(indPin, HIGH);
analogWrite(pwmPin, nobeam);
delay(msdelay);
analogWrite(pwmPin, highbeam);
delay(msdelay);
analogWrite(pwmPin, nobeam);
delay(msdelay);
analogWrite(pwmPin, highbeam);
digitalWrite(indPin, LOW);
hasBlinked=1;
//lastDebounceTime = millis();
}
The time returned by millis() is an unsigned long (32 bits), but you're saving it the lastXXXX that is only an int (16 bits, on AVR. Plus you didn't specify "unsigned", so it's more like 15 bits.))
This will cause various sorts of unexpected behavior. 32768 milliseconds (15bits worth) is only about 33 seconds. (32bits worth of milliseconds is about 5 weeks. And you can actually avoid problems when it runs out, if you're careful. In this case, it's the mismatch between the two types causing the problem, rather than less obvious algorithm problems.
Make all the variables where you store millis() be "unsigned long" instead of int, and your problems should disappear.
(This is likely to be a common mistake for programmers coming from other platforms. On almost any other computer, an "int" is also 32 bits.)