Saving a pulse/count position from my motor encoder

Hi!

These arrays, are they necessary even when i just want to save ONE number?
All I want to save in the memory is one position (one number), never more.

Now, I want to press a button, to store this position.
Boink, the number 768 is stored in memory for UNO to later do something with.

Then, when I go by/passes this number again, 768, I want the motor to stop.

The motor will never go past that position again because the pulse counter will be incremented each time passing the "encoder" vane. However, if say 4 is added to the pulse counter for each revolution, then the motor will be in the same place when the count gets to 772

So, have the motor running and count pulses.
Detect when the "stop" button becomes pressed
save the value of the pulse counter and stop the motor
Start the motor with another button press
Keep going until the pulse counter equals the saved value plus the number of pulses per revolution.

Whilst the logic may be OK the solution is full of holes

1 - the motor will overun when you stop it if you don't apply braking
2 - you appear to have only 4 encoder vanes which means that the system will not be very accurate
3 - are you detecting when the encoder beam becomes interrupted or when it is interrupted ?

Hi!

But there is no STOP button?

There is one "GO" button, and the motor stops when the button is released. Not when some button is pressed. How to do then?

The decoder has multiple sensors, so it read when its both HIGH and LOW.
So it knows wich direction it can go. So it should be quite precise.
It can be used as a stepmotor in the same way. And it cound the pulses very precisely even when going very fast.

Something like this maybe?

// MEMORYTEST FOR SAVING EEPROM -=-=-=-=-=-=-=-=-=-=-=-=- else { val = digitalRead(intest3Pin); // Button 3 - Shall save in memory if (val == HIGH) { // Checks if button is pressed

EEPROM.write(PulseCount); // Writes PulseCount number to memory
lcd.setCursor(0, 1); // These 2 lines writes to LCD
lcd.print(“Pos SAVED!”);
}
}

Something like this maybe?

Did that compile? I doubt it. When you write something to EEPROM, you have to say what to write AND where to write it.

Ok... No it didnt compile.
It complains already at the 'else' :frowning:

Is there a standard adress I can use then?
How do I write this?
(I'm a newbie to this)

It complains already at the 'else' :frowning:

Pay a visit to these fine folks, for help with snippets: http://snippets-r-us.com

Is there a standard adress I can use then?

Or was that 42? I can never remember.

Use any address you want.

How do I write this?

The reference page is chock full of useful information.

OKEY! - Some Progress-
Now I can with a button save a position, and with the other button recall this number on the LCD.
BUT! It only works when the number is within 0 and -255, so Im reaching some kind of limit here.
Ill bet it has something to do with bits and bytes.
How can extend this?

// MEMORYTEST FOR SAVING TO EEPROM -=-=-=-=-=-=-=-=-=-=-=-=-


 {
  val = digitalRead(intest3Pin);         // Button 3 - Shall save in memory
  if (val == HIGH) {                     // Checks if button is pressed

EEPROM.write(0,PulseCount);                // Writes PulseCount number to memory, adress is 0
    lcd.setCursor(0, 1);                 // These 2 lines writes to LCD
    lcd.print(PulseCount);
        delay(750);
            lcd.setCursor(0, 1);                 // These 2 lines writes to LCD
    lcd.print("Pos Saved!");
        delay(750);
  }     
}


// MEMORYTEST FOR READING FROM EEPROM -=-=-=-=-=-=-=-=-=-=-=-=-

 {
  val = digitalRead(intest4Pin);         // Button 4 - Shall save in memory
  if (val == HIGH) {                     // Checks if button is pressed

EEPROM.get(0,PulseCount);                // Reads PulseCount number to memory, adress is 0
    lcd.setCursor(0, 1);                 // These 2 lines writes to LCD
    lcd.print(0);                        // 0 is adress
        delay(1000);
  }     
}

EEPROM.put solved it, instead of EEPROM.write

Ill bet it has something to do with bits and bytes.

Exactly. A byte is 8 bits. That's what EEPROM.write() writes.

An int is 16 bits, or two bytes. You could use two calls to EEPROM.write(), to write the low order byte and the high order byte. That's what put() does, for an int.

Post your complete program as it is now and remind us what you want to do and where you are stuck