Disclaimer:
I am a complete beginner and I apologize in advance if these are stupid questions.
Background:
I have been looking at the "Blink without delay" example in the Arduino IDE, and I wrote a short piece of code in an attempt to understand what happens to the timing of the blink when the millis() function reaches the end of its 49 day lifespan.
The interesting part is when [small number]-[big number]=[positive number]. I am trying to understand how the unsigned long variables in this equation make the answer positive.
-
And more importantly, why does my short sketch make the built-in LED on pin 13 glow. I have not called the Pin13 or the LED_BUILTIN.
-
Is this caused by "runaway" voltage or "noise", and should I be worried about that? (I.e. would it drain battery over time?)
-
If I tell pin 13 to shut up with a digital write(13, LOW), where will this electrical noise energy go?
Hardware:
Arduino UNO R3
**My code: ** Actually it doesnt matter what the code is. See edit below.
unsigned long previousMillis = 4294967295;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(10 - previousMillis);
//Serial.println(millis());
delay(3000);
}
The Blink without delay example: (just for reference):
// constants won't change. Used here to set a pin number:
const int ledPin = LED_BUILTIN;// the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 5000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the difference
// between the current time and last time you blinked the LED is bigger than
// the interval at which you want to blink the LED.
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
Edit: I noticed the code I posted is not the reason. The glow happens even with a bare minimum sketch.