Changing state with nano

Is it possible your LED is a back to back LED ? (i.e. lights in both positions)

You'd have to color blind not to see if it was back to back, unless the LEDs were identical, in which case that's another part for which the data sheet comes out on the first day of the fourth month…

a7

still doesn't compile. assignment of read only variable "state"

I use these leds all the time and the one I'm using now was just used in a fade sketch without fail.

Damn
const byte state = LOW;
should read:
byte state = LOW;

works as expected thank you , why didnt the other state change work? Just wondering now.

no camera on my puter either

ah alas no wife either

Hey, you editing the sketch in the earlier post?

But I wonder if the compiler warns about

state = !state;

If state is const.

a7

works as expected thank you , why didnt the other state change work? Just wondering now.

It should work the way you have it i.e. on pin 10.

Well its only 8 months to Christmas.

alto we may be tripping all over each other but the sketch presented by larryD is working fine, My original question is still open,
thank you for your help.

LarryD you are correct, Christmas is indeed coming. I have cameras but none available. In fact: my arduino project revolves around those camera.

UKHeliBob: thank you for your response, I credited the sketch to the wrong person, You are the author of the sketch I posted. I have tried it on my nano and it does not seem to function as expected. I am trying to figure out why it doesn't work. NO real answer so far. thanks I have corrected the credit for the sketch, My apologies.

Arduino Mini Nano V3.0 ATmega328P 5V 16M

I expect it to flash, it does not it just lights up and stays lit.
sorry for the late reply

Are you saying it works if you use state and it does not if you use the digitalRead?

I believe that’s what he reported.

I don’t have a Nano so cannot prove it here.

The controller is the same :woozy_face:

JML yes it works with state but not with digitalWrite, I use a clone nano r3 I don't know if that makes a difference.

Can you try this with the serial monitor opened at 115200 bauds


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
    Serial.println(digitalRead(ledPin));  // let’s see what’s read
    state = (state == LOW) ? HIGH : LOW;
    startMillis = currentMillis;  //IMPORTANT to save the start time of the current LED state.
  }
}

Which version of the IDE are you using?

JML I will try that tomorrow i have shut down arduino for tonight thank you.