this line edited: I am using a sample program from UKHeliBob
For some reason it doesn't work for me.
I am using a nano so my question is: will this line work with a nano:
digitalWrite(ledPin, ! digitalRead(ledPin));
unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 3000; //the value is a number of milliseconds
const byte ledPin = 10; //using the built in LED
void setup()
{
Serial.begin(115200); //start Serial in case we need to print debugging info
pinMode(ledPin, OUTPUT);
startMillis = millis(); //initial start time
}
void loop()
{
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
digitalWrite(ledPin, ! digitalRead(ledPin)); //if so, change the state of the LED. Uses a neat trick to change the state
startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}
ya I see it says 10 now, I changed it from 13 to 10 trying to utilize a different pin to zero in on the problem. it doesn't work on 10 or 13. it this a nano thing?
I don't have the pullup resistor in the pin but it is already high. I assume because it is on all the time. Please feel free to correct me if im wrong.
unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 3000; //the value is a number of milliseconds
const byte ledPin = 10; //using the built in LED
byte state = LOW;
void setup()
{
Serial.begin(115200); //start Serial in case we need to print debugging info
pinMode(ledPin, OUTPUT);
startMillis = millis(); //initial start time
}
void loop()
{
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
digitalWrite(ledPin, state); //if so, change the state of the LED. Uses a neat trick to change the state
state = !state;
startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}