Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 23, 2014, 08:11:18 am
Hey all,

I took a little time out from the postings here - and as suggested i started reading and trying to understand and I finally solved it. The whole code I had was all messed up and needed little moving around, but it's all good now.

I just want to thank all of you for the help and say I'm sorry for expanding this topic on and on.

Thanks again!
2  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 05, 2014, 06:48:02 am
Code:
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A0);
int sensorValue3 = analogRead(A0);
This is useless. At compile time, the value read from pin A0 is meaningless. Just set these to 0.

Code:
int sensorVal[] = { 0, lo1Word, lo2Word, lo3Word, 1023 };
More uselessness. lo1Word, lo2Word, and lo3Word are 0.

Quote
Before I read them of course.
Then, you are a bigger idiot than I thought.

I meant reading the values before only storing 0s is what you were asking.

Well then how can I first ask from the program to read the values, and store them in sensorVal, I guess that's the only thing left to do.
3  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 05, 2014, 06:32:44 am
Quote
Then, think about WHEN you need to store the values in the array. Should you store the values in the array BEFORE you read them, as you are doing now? Or, should you store the values in the array AFTER you read them?

Before I read them of course.

Quote
What problems are you having with your current code.?

Well, the values that I assigned in loWord1, 2 and 3 were all 0's because I read them before there was anything written in them.

Now, I've moved mappedValue[], and sensorVal[] in the loop function, after the variables declaration but it's still the same.

Because at the beginning there's nothing in the variables, it will still assign them 0 values, I suppose. I need to assign the values in the mapping functions the values that I've read when pressing the buttons. Maybe the multiMap function at the end is having some mistakes, but I took it from the arduino website.

Have you run my code? Do you understand what I'm trying to achieve. I feel like I'm not clear enough and you still don't know what I'm trying to achieve.

Here's the code

Code:
#include <EEPROM.h>

int buttonPin1 = 8;
int buttonPin2 = 9;
int buttonPin3 = 10;

int lo1Word, lo2Word, lo3Word;
int buttonState1;
int buttonState2;
int buttonState3;

int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A0);
int sensorValue3 = analogRead(A0);

int mappedValue[] = {0, 0, 20, 40, 40 };
int sensorVal[] = { 0, lo1Word, lo2Word, lo3Word, 1023 };

int meters;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int val = analogRead(14);
  sensorValue1 = analogRead(A0);
  byte myHigh1 = highByte(sensorValue1);
  byte myLow1 = lowByte(sensorValue1);

  sensorValue2 = analogRead(A0);
  byte myHigh2 = highByte(sensorValue2);
  byte myLow2 = lowByte(sensorValue2);
 
  sensorValue3 = analogRead(A0);
  byte myHigh3 = highByte(sensorValue3);
  byte myLow3 = lowByte(sensorValue3);
 
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
 
  Serial.print("Sensor 1 : "); 
  Serial.println(sensorValue1);
 
  Serial.print("Sensor 2 : "); 
  Serial.println(sensorValue2);
 
  Serial.print("Sensor 3 : "); 
  Serial.println(sensorValue3);
 
  delay(500);
 
  if(buttonState1 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(10, myHigh1);
    EEPROM.write(11, myLow1);
    lo1Word = word(myHigh1, myLow1);
  }
  else if (buttonState1 == LOW)
    Serial.print("");
   
  if(buttonState2 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(12, myHigh2);
    EEPROM.write(13, myLow2);
    lo2Word = word(myHigh2, myLow2);
  }
  else if (buttonState2 == LOW)
    Serial.print("");
   
  if(buttonState3 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(14, myHigh3);
    EEPROM.write(15, myLow3);
    lo3Word = word(myHigh3, myLow3);
  }
  else if (buttonState3 == LOW)
    Serial.print("");
   
  sensorValue1 = word(EEPROM.read(10), EEPROM.read(11));
  sensorValue2 = word(EEPROM.read(12), EEPROM.read(13));
  sensorValue3 = word(EEPROM.read(14), EEPROM.read(15));
 
  Serial.println(" ----------- ");
  Serial.print("Sensor Value 1 : ");
  Serial.println(sensorValue1);
 
  Serial.print("Sensor Value 2 : ");
  Serial.println(sensorValue2);
 
  Serial.print("Sensor Value 3 : ");
  Serial.println(sensorValue3);
 
  Serial.println(" ---------- ");
 
  delay(1500);
 
  meters = multiMap(val, sensorVal, mappedValue, 5);
 
  Serial.print("Meters : ");
  Serial.println(meters);
}
 
 
int multiMap(int meters, int* sensorVal, int* mappedValue, uint8_t size)
{
  // take care the value is within range
  // val = constrain(val, _in[0], _in[size-1]);
  if (meters <= sensorVal[0]) return mappedValue[0];
  if (meters >= sensorVal[size-1]) return mappedValue[size-1];

  // search right interval
  uint8_t pos = 1;  // _in[0] allready tested
  while(meters > sensorVal[pos]) pos++;

  // this will handle all exact "points" in the _in array
  if (meters == sensorVal[pos]) return mappedValue[pos];

  // interpolate in the right segment for the rest
  return map(meters, sensorVal[pos-1], sensorVal[pos], mappedValue[pos-1], mappedValue[pos]);
}
4  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 03:38:14 pm
Quote
That seems no different to me than being consistent using lowByte() and highByte() and reading and writing.
Yes but then anyone could understand it and the software types would loose a bit of mystique.

See how my simple solution at the top of page 2 is being totally ignored.

I didn't ignore it, I just wanted to see if I can make it work with the previous example, and after a while I wrote something and truth is I don't really know if it will work like this. How will I read the value back?

Code:
#include <EEPROM.h>

int buttonPin1 = 8;
int buttonPin2 = 9;
int buttonPin3 = 10;

int buttonState1;
int buttonState2;
int buttonState3;

int sensorValue1;
int sensorValue2;
int sensorValue3;


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  sensorValue1 = analogRead(A0);
  sensorValue2 = analogRead(A0);
  sensorValue3 = analogRead(A0);
 
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
 
  Serial.print("Sensor 1 : "); 
  Serial.println(sensorValue1);
 
  Serial.print("Sensor 2 : "); 
  Serial.println(sensorValue2);
 
  Serial.print("Sensor 3 : "); 
  Serial.println(sensorValue3);
 
  delay(500);
 
  if(buttonState1 == HIGH)
  {
    Serial.println("Button pressed");
    write_int_to_EEPROM(10, sensorValue1);   
  }
  else if (buttonState1 == LOW)
    Serial.print("");
   
  if(buttonState2 == HIGH)
  {
    Serial.println("Button pressed");
    write_int_to_EEPROM(14, sensorValue2);
  }
  else if (buttonState2 == LOW)
    Serial.print("");
   
  if(buttonState3 == HIGH)
  {
    Serial.println("Button pressed");
    write_int_to_EEPROM(16, sensorValue3);
  }
  else if (buttonState3 == LOW)
    Serial.print("");
}

void write_int_to_EEPROM(int point, int Value)
{
  point = point * 2;
  EEPROM.write(point, Value & 0xff);
  EEPROM.write(point+1, Value >> 8);
}
5  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 12:54:58 pm
Yes, you are right, all the values assigned are 0.

My problem is that the values that need to be put in sensorVal[] MUST be the values that are being read from the potentiometer when the respective button is pressed, and the stored in sensorVal[].

I thought about using the arduino word function, adding 3 new variables, lo1Word, lo2Word, lo3Word, and they all read the sensor values, and convert them, then they are stored in the sensorVal, but it still doesn't work.

Here is the code.


Code:
#include <EEPROM.h>

int buttonPin1 = 8;
int buttonPin2 = 9;
int buttonPin3 = 10;

[b]int lo1Word, lo2Word, lo3Word;
[/b]
int buttonState1;
int buttonState2;
int buttonState3;

int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A0);
int sensorValue3 = analogRead(A0);

int mappedValue[] = {0, 0, 20, 40, 40 };
int sensorVal[] = { 0, [b]lo1Word, lo2Word, lo3Word[/b], 1023 };

int meters;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int val = analogRead(14);
  sensorValue1 = analogRead(A0);
  byte myHigh1 = highByte(sensorValue1);
  byte myLow1 = lowByte(sensorValue1);

  sensorValue2 = analogRead(A0);
  byte myHigh2 = highByte(sensorValue2);
  byte myLow2 = lowByte(sensorValue2);
 
  sensorValue3 = analogRead(A0);
  byte myHigh3 = highByte(sensorValue3);
  byte myLow3 = lowByte(sensorValue3);
 
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
 
  Serial.print("Sensor 1 : "); 
  Serial.println(sensorValue1);
 
  Serial.print("Sensor 2 : "); 
  Serial.println(sensorValue2);
 
  Serial.print("Sensor 3 : "); 
  Serial.println(sensorValue3);
 
  delay(500);
 
  if(buttonState1 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(10, myHigh1);
    EEPROM.write(11, myLow1);
[b]    lo1Word = word(myHigh1, myLow1);[/b]  }
  else if (buttonState1 == LOW)
    Serial.print("");
   
  if(buttonState2 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(12, myHigh2);
    EEPROM.write(13, myLow2);
    [b]lo2Word = word(myHigh2, myLow2);[/b]
  }
  else if (buttonState2 == LOW)
    Serial.print("");
   
  if(buttonState3 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(14, myHigh3);
    EEPROM.write(15, myLow3);
    [b]lo3Word = word(myHigh3, myLow3);[/b]
  }
  else if (buttonState3 == LOW)
    Serial.print("");
   
  sensorValue1 = word(EEPROM.read(10), EEPROM.read(11));
  sensorValue2 = word(EEPROM.read(12), EEPROM.read(13));
  sensorValue3 = word(EEPROM.read(14), EEPROM.read(15));
 
  Serial.println(" ----------- ");
  Serial.print("Sensor Value 1 : ");
  Serial.println(sensorValue1);
 
  Serial.print("Sensor Value 2 : ");
  Serial.println(sensorValue2);
 
  Serial.print("Sensor Value 3 : ");
  Serial.println(sensorValue3);
 
  Serial.println(" ---------- ");
 
  delay(1500);
 
  meters = multiMap(val, sensorVal, mappedValue, 5);
 
  Serial.print("Meters : ");
  Serial.println(meters);
}
 
 
int multiMap(int meters, int* sensorVal, int* mappedValue, uint8_t size)
{
  // take care the value is within range
  // val = constrain(val, _in[0], _in[size-1]);
  if (meters <= sensorVal[0]) return mappedValue[0];
  if (meters >= sensorVal[size-1]) return mappedValue[size-1];

  // search right interval
  uint8_t pos = 1;  // _in[0] allready tested
  while(meters > sensorVal[pos]) pos++;

  // this will handle all exact "points" in the _in array
  if (meters == sensorVal[pos]) return mappedValue[pos];

  // interpolate in the right segment for the rest
  return map(meters, sensorVal[pos-1], sensorVal[pos], mappedValue[pos-1], mappedValue[pos]);
}
6  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 12:04:02 pm
Well, the meters value that is being outputed needs to change as the potentiometer changes, as I said earlier - first I write the values sensorVal1, sensorVal2, and sensorVal3, and from those values it needs to make a scale.

So, when I load the program again, the meters variable which is outputed needs to change from 0 to 40, while in my case it's 40 all the time except when the potentiometer value is 0, then the meters variable equals 0.

Why doesn't it change respectively?
7  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 11:01:25 am
After writing in the correct order, the values that are saved are correct.

But I got another problem. I needed saving the values to the EEPROM for multi mapping.

I have the three saved values in the eeprom, for example VAR 1 = 200, VAR2  = 500, and VAR3 = 1023 so now I need to make a scale if you would that would go from the 3 give variables (VAR1, VAR2, and VAR3) so that VAR1 will be 0 - or the beginning of the scale and VAR3 will be the max value.

I checked out the multiMap function for arduino and used the code, I have attached my whole program.

Code:
#include <EEPROM.h>

int buttonPin1 = 8;
int buttonPin2 = 9;
int buttonPin3 = 10;

int buttonState1;
int buttonState2;
int buttonState3;

int sensorValue1;
int sensorValue2;
int sensorValue3;

int mappedValue[] = {0, 0, 20, 40, 40 };
int sensorVal[] = { 0, sensorValue1, sensorValue2, sensorValue3, 1023 };

int meters;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int val = analogRead(14);
  sensorValue1 = analogRead(A0);
  byte myHigh1 = highByte(sensorValue1);
  byte myLow1 = lowByte(sensorValue1);

  sensorValue2 = analogRead(A0);
  byte myHigh2 = highByte(sensorValue2);
  byte myLow2 = lowByte(sensorValue2);
 
  sensorValue3 = analogRead(A0);
  byte myHigh3 = highByte(sensorValue3);
  byte myLow3 = lowByte(sensorValue3);
 
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
 
  Serial.print("Sensor 1 : "); 
  Serial.println(sensorValue1);
 
  Serial.print("Sensor 2 : "); 
  Serial.println(sensorValue2);
 
  Serial.print("Sensor 3 : "); 
  Serial.println(sensorValue3);
 
  delay(500);
 
  if(buttonState1 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(10, myHigh1);
    EEPROM.write(11, myLow1);
  }
  else if (buttonState1 == LOW)
    Serial.print("");
   
  if(buttonState2 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(12, myHigh2);
    EEPROM.write(13, myLow2);
  }
  else if (buttonState2 == LOW)
    Serial.print("");
   
  if(buttonState3 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(14, myHigh3);
    EEPROM.write(15, myLow3);
  }
  else if (buttonState3 == LOW)
    Serial.print("");
   
  sensorValue1 = word(EEPROM.read(10), EEPROM.read(11));
  sensorValue2 = word(EEPROM.read(12), EEPROM.read(13));
  sensorValue3 = word(EEPROM.read(14), EEPROM.read(15));
 
  Serial.println(" ----------- ");
  Serial.print("Sensor Value 1 : ");
  Serial.println(sensorValue1);
 
  Serial.print("Sensor Value 2 : ");
  Serial.println(sensorValue2);
 
  Serial.print("Sensor Value 3 : ");
  Serial.println(sensorValue3);
 
  Serial.println(" ---------- ");
 
  delay(1500);
 
  meters = multiMap(val, sensorVal, mappedValue, 5);
 
  Serial.print("Meters : ");
  Serial.println(meters);
}
 
 
int multiMap(int meters, int* sensorVal, int* mappedValue, uint8_t size)
{
  // take care the value is within range
  // val = constrain(val, _in[0], _in[size-1]);
  if (meters <= sensorVal[0]) return mappedValue[0];
  if (meters >= sensorVal[size-1]) return mappedValue[size-1];

  // search right interval
  uint8_t pos = 1;  // _in[0] allready tested
  while(meters > sensorVal[pos]) pos++;

  // this will handle all exact "points" in the _in array
  if (meters == sensorVal[pos]) return mappedValue[pos];

  // interpolate in the right segment for the rest
  return map(meters, sensorVal[pos-1], sensorVal[pos], mappedValue[pos-1], mappedValue[pos]);
}


Thanks a lot for the help.
8  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 06:20:40 am
Sorry, here's the code.

Code:
#include <EEPROM.h>

int buttonPin1 = 8;
int buttonPin2 = 9;
int buttonPin3 = 10;

int buttonState1;
int buttonState2;
int buttonState3;

int sensorValue1;
int sensorValue2;
int sensorValue3;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  sensorValue1 = analogRead(A0);
  byte myHigh1 = highByte(sensorValue1);
  byte myLow1 = lowByte(sensorValue1);

  sensorValue2 = analogRead(A0);
  byte myHigh2 = highByte(sensorValue2);
  byte myLow2 = lowByte(sensorValue2);
 
  sensorValue3 = analogRead(A0);
  byte myHigh3 = highByte(sensorValue3);
  byte myLow3 = lowByte(sensorValue3);
 
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
 
  Serial.print("Sensor 1 : "); 
  Serial.println(sensorValue1);
 
  Serial.print("Sensor 2 : "); 
  Serial.println(sensorValue2);
 
  Serial.print("Sensor 3 : "); 
  Serial.println(sensorValue3);
 
  delay(500);
 
  if(buttonState1 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(10, myHigh1);
    EEPROM.write(11, myLow1);
  }
  else if (buttonState1 == LOW)
    Serial.print("");
   
  if(buttonState2 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(12, myHigh2);
    EEPROM.write(13, myLow2);
  }
  else if (buttonState2 == LOW)
    Serial.print("");
   
  if(buttonState3 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(14, myHigh3);
    EEPROM.write(15, myLow3);
  }
  else if (buttonState3 == LOW)
    Serial.print("");
   
  sensorValue1 = word(EEPROM.read(11), EEPROM.read(10));
  sensorValue2 = word(EEPROM.read(13), EEPROM.read(12));
  sensorValue3 = word(EEPROM.read(15), EEPROM.read(14));
 
  Serial.print("Sensor Value 1 : ");
  Serial.println(sensorValue1);
 
  Serial.print("Sensor Value 2 : ");
  Serial.println(sensorValue2);
 
  Serial.print("Sensor Value 3 : ");
  Serial.println(sensorValue3);
 
  delay(1000);
}
9  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 06:15:00 am
@PaulS
- I added the high and low bytes in the loop function, and now it saves values like Sensor Value 1 : -28159, Sensor Value 2 : -28671 etc while the sensor value really is 500.

@Grumpy_Mike
- I will try it out and post the results.
10  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 05:20:28 am
Okay, so I added three buttons in the code and I would like to explain once again so that there are absolutely no misunderstandings.

In the code bellow, I have three buttons, attached on pins 8, 9, and 10.

There are 3 int variables, the sensor values. I tried to convert the values using high and low bytes but I failed.

Then, as you can see, when I press the first button, I need to save the value of the potentiometer in EEPROM under adresses 10 and 11, and later read it using the sensorValue1 variable.

The same principle applies for the rest of the buttons and variables.

At the end, when outputting, the sensor values are all zeros.


Code:
#include <EEPROM.h>

int buttonPin1 = 8;
int buttonPin2 = 9;
int buttonPin3 = 10;

int buttonState1;
int buttonState2;
int buttonState3;

int sensorValue1;
byte myHigh1 = highByte(sensorValue1);
byte myLow1 = lowByte(sensorValue1);

int sensorValue2;
byte myHigh2 = highByte(sensorValue2);
byte myLow2 = lowByte(sensorValue2);

int sensorValue3;
byte myHigh3 = highByte(sensorValue3);
byte myLow3 = lowByte(sensorValue3);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  sensorValue1 = analogRead(A0);
  sensorValue2 = analogRead(A0);
  sensorValue3 = analogRead(A0);
 
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
 
  Serial.print("Sensor 1 : "); 
  Serial.println(sensorValue1);
 
  Serial.print("Sensor 2 : "); 
  Serial.println(sensorValue2);
 
  Serial.print("Sensor 3 : "); 
  Serial.println(sensorValue3);
 
  delay(500);
 
  if(buttonState1 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(10, myHigh1);
    EEPROM.write(11, myLow1);
  }
  else if (buttonState1 == LOW)
    Serial.print("");
   
  if(buttonState2 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(12, myHigh2);
    EEPROM.write(13, myLow2);
  }
  else if (buttonState2 == LOW)
    Serial.print("");
   
  if(buttonState3 == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(14, myHigh3);
    EEPROM.write(15, myLow3);
  }
  else if (buttonState3 == LOW)
    Serial.print("");
   
  sensorValue1 = word(EEPROM.read(11), EEPROM.read(10));
  sensorValue2 = word(EEPROM.read(13), EEPROM.read(12));
  sensorValue3 = word(EEPROM.read(15), EEPROM.read(14));
 
  Serial.print("Sensor Value 1 : ");
  Serial.println(sensorValue1);
 
  Serial.print("Sensor Value 2 : ");
  Serial.println(sensorValue2);
 
  Serial.print("Sensor Value 3 : ");
  Serial.println(sensorValue3);
 
  delay(1000);
}


@econjack
- I have a fair understanding in programming, mostly C++, and I know what your code does, I need to study it further yes, if this example doesn't work I'll surely dive more into it. Thanks for the help.

@AWOL
- Yes, I have, although I don't know how to access only the variables I need with this line :
Code:
if (digitalRead(13) == HIGH)
      eeprom_write_block((const void*)&settings, (void*)0, sizeof(settings));
Because as you see, mostly I need to manipulate several variables with one or several buttons. How can I only write one variable instead of the whole settings struct?
11  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 03, 2014, 10:00:14 am
@econjack

I tried your example but how will I implement this for my EEPROM problem? This reads temporary value and doesn't store it anywhere.
12  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 03, 2014, 09:40:42 am
Here is the code I have. I added the word function, which from the documentation should be written correctly, but it only outputs 0, nothing happens.

Code:
#include <EEPROM.h>

int buttonPin = 8;
int buttonState;

int sensorValue;
byte myHigh = highByte(sensorValue);
byte myLow = lowByte(sensorValue);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  sensorValue = analogRead(A0);
  buttonState = digitalRead(buttonPin);
  Serial.println(sensorValue);
  delay(500);
 
  if(buttonState == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(10, word(myHigh, myLow));
  }
  else if (buttonState == LOW)
    Serial.print("");
 
    Serial.print("EEPROM VALUE : ");
    Serial.println(EEPROM.read(10));
}
13  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 03, 2014, 08:27:00 am
This is a reply from a forum member

Code:
int test = 0xABCD;   // 16 bits
byte hi, lo;  // 8 bits each

hi = HighByte(test);  //in case you're wondering this should be 0xAB
lo = LowByte(test);    // and this should be 0xCD.

So basically, he wrote a hex value in the int variable? Do I have to do that? Because I don't know the exact value of the potentiometer, I know the value the moment when I press the button, so how do I convert that value to hi and lo bytes?
14  Using Arduino / Programming Questions / Writing potentiometer value to EEPROM over 255 [SOLVED] on: August 03, 2014, 07:16:05 am
Hi everyone,

I have read many discussions on this topic, but I have a more particular problem. I need to save a value to EEPROM that I've read from the potentiometer, from 0 to 1023.

If the value is over 255, it automatically saves it as 255, due to being 8 bytes. What is the solution for this?

Here is the code :

Code:
#include <EEPROM.h>

int buttonPin = 8;
int buttonState;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  delay(100);
  
  if(buttonState == HIGH)
  {
    Serial.println("Button pressed");
    EEPROM.write(10, sensorValue);
  }
  else if (buttonState == LOW)
    Serial.print("");
    
    Serial.print("EEPROM VALUE : ");
    Serial.println(EEPROM.read(10));
}

Thanks and all the best.
15  Using Arduino / Project Guidance / Re: Arduino multivalue problem on: August 02, 2014, 08:27:02 am
Never mind, I got it working. Thank you very much for your help.
Pages: [1] 2 3