Hi all
Can anyone help me out with this seemingly none complicated problem.
I've created a C# program to send serial data to a Teensy 3.2. On the Teensy there is the code below. The idea is that when the Teensy detects a string, RESI_A for example, a float number is put into the EEPROM.
The code seems to work for any one if statement, but when I try a different if statement the data in the other addresses gets screwed up. Bizarre...
For example when I put a float in a specific address, the data in the other addresses seems to get screwed up..
Can anyone see my mistake?
Can anyone help me out with this seemingly none complicated problem.
I've created a C# program to send serial data to a Teensy 3.2. On the Teensy there is the code below. The idea is that when the Teensy detects a string, RESI_A for example, a float number is put into the EEPROM.
The code seems to work for any one if statement, but when I try a different if statement the data in the other addresses gets screwed up. Bizarre...
For example when I put a float in a specific address, the data in the other addresses seems to get screwed up..
Can anyone see my mistake?
Code:
#include <EEPROM.h>
String val;
float RESI_A = 1.0f;
float RESI_B = 1.1f;
float RESI_C = 1.2f;
float RESI_D = 1.3f;
float EEPROMA;
float EEPROMB;
float EEPROMC;
float EEPROMD;
void setup() {
Serial.begin(9600);
val = "NONE";
}
void loop() {
if (Serial.available()){
val = Serial.readString();
if (val == "1")
{
EEPROM.put(0, RESI_A); //Write the value to the appropriate byte of the EEPROM.
}
else if (val == "2")
{
EEPROM.put(1, RESI_B); //Write the value to the appropriate byte of the EEPROM.
}
else if (val == "3")
{
EEPROM.put(2, RESI_C); //Write the value to the appropriate byte of the EEPROM.
}
else if (val == "4")
{
EEPROM.put(3, RESI_D); //Write the value to the appropriate byte of the EEPROM.
}
}
val = "NONE";
}