the LED program
then I made this program that will compare the EEPROM value to num.4 and compares the F variable to num.4 known that both F and the EEPROM values are 4. and then I changed both of the values to 3. shouldn't the GREEN LED of the EEPROM still on because it has already stored num.4??
#include<EEPROM.h>
void setup()
{
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
EEPROM.write(0,4); //GREEN LED
int f=4; //RED LED
if(EEPROM.read(0)==4)
digitalWrite(12,HIGH);
if(f==4)
digitalWrite(11,HIGH);
}
}
void loop()
{
When the EEPROM contains 3 and it is compared with 4, then they are not the same.
We would like to see a sketch that shows the problem, but you show the sketch that does not have a problem.
I think this is easier to test with the serial monitor.
#include<EEPROM.h>
const int greenLedPin = 12;
const int redLedPin = 11;
void setup()
{
Serial.begin( 9600);
Serial.println( "-------------------------------------------");
pinMode( greenLedPin, OUTPUT);
pinMode( redLedPin, OUTPUT);
// Show what was previously stored in EEPROM
byte value0 = EEPROM.read( 0);
byte value1 = EEPROM.read( 1);
Serial.print( "EEPROM location 0 : ");
Serial.print( value0);
if( value0 == 4)
{
Serial.print( " (it is equal to 4)");
}
else
{
Serial.print( " (it is not equal to 4)");
}
Serial.println();
Serial.print( "EEPROM location 1 : ");
Serial.print( value1);
if( value1 == 100)
{
Serial.print( " (it is equal to 100)");
}
else
{
Serial.print( " (it is not equal to 100)");
}
Serial.println();
// Store a new number in location 0 and 1 of the EEPROM
// The randomSeed() is used to make a different random number after restarting.
randomSeed( word( value0, value1) + analogRead( A0) + analogRead( A1));
byte newValue0 = 3 + (byte) random( 0, 3);
byte newValue1 = 98 + (byte) random( 0, 5);
EEPROM.write( 0, newValue0);
EEPROM.write( 1, newValue1);
Serial.print( "New values have been written (");
Serial.print( newValue0);
Serial.print( " and ");
Serial.print( newValue1);
Serial.println( ")");
Serial.println( "Press reset or disconnect power and see what happens next time");
}
void loop()
{
}