-
面包板 略
-
原理图 略
-
PCB 略
-
ArduBlock
image.png -
Arduino
#include <EEPROM.h>
/********************************************************
* A way to read int (2 Bytes)from EEPROM
* EEPROM library natively supports only bytes
********************************************************/
int eepromReadInt(int address){
union u_tag {
byte b[2];
int INTtime;
}
time;
time.b[0] = EEPROM.read(address);
time.b[1] = EEPROM.read(address+1);
return time.INTtime;
}
/*******************************************************************
* A way to write an 'int' (2 Bytes) to EEPROM
* EEPROM library natively supports only bytes.
* Note it takes around 8ms to write an int to EEPROM
*******************************************************************/
void eepromWriteInt(int address, int value){
union u_tag {
byte b[2]; //assumes 2 bytes in an int
int INTtime;
}
time;
time.INTtime=value;
EEPROM.write(address , time.b[0]);
EEPROM.write(address+1, time.b[1]);
}
void setup()
{
Serial.begin(9600);
Serial.print("Read from Arduino");
Serial.println();
Serial.print(eepromReadInt( 10 ) );
Serial.println();
Serial.print(eepromReadInt( 11 ) );
Serial.println();
Serial.print(eepromReadInt( 12 ) );
Serial.println();
Serial.print(eepromReadInt( 13 ) );
Serial.println();
Serial.print(eepromReadInt( 14 ) );
Serial.println();
delay( 1000 );
eepromWriteInt( 10 , 1 ) ;
eepromWriteInt( 11 , 2 ) ;
eepromWriteInt( 12 , 3 ) ;
eepromWriteInt( 13 , 4 ) ;
eepromWriteInt( 14 , 5 ) ;
}
void loop()
{
}
网友评论