Help with EEPROM.get please.

I don't understand, the function counter does work.

cattledog:
Yes, that the way the sketch works.

Oh, is there a way to assign paramx_pulses to their respective paramx_value on start up? It won't be feasible to toggle through the menu each time.

Oh, is there a way to assign paramx_pulses to their respective paramx_value on start up?

Add the assignments int setup as I have done below. I'm not sure what you want to do with the param2_index.

You may want to pull the restore = 1 command out of the cases, as you will have done that in setup. The value of restore is actually managed when you access the cases with the function control. You are the one who knows what you want to change with the encoder counts, and what you want to restore from saved settings.

#include <Arduino.h>
#include <pins_arduino.h>
#include <Wire.h>
#include "AidaDSP.h"
#include <LiquidCrystal.h>
#include <EEPROM.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7); //RS, E, D4, D5, D6, D7

const int SAVE = 14;

#define EVER (;;)

// DEFINES I/O
#define PIN_LED  13

// DEFINES USER INTERFACE
#define MAX 20.00
#define MIN -40.00

#define ON 1
#define OFF 0

// FUNCTION PROTOTYPES
void spettacolino(void);
void clearAndHome(void);

// GLOBAL VARIABLES

// UI
uint8_t bypass = OFF;
uint8_t oldbypass = OFF;
uint8_t func_counter = 0;
uint8_t old_func_counter = 0;
uint8_t push_e_count = 0;
uint8_t push_e_function = 0;
uint8_t restore = 0;

uint16_t param2_index = 1;

int32_t param1_pulses = 0;
int32_t param2_pulses = 0;
int32_t param3_pulses = 0;
int32_t param4_pulses = 0;

uint32_t timec=0, prevtimec=0;

float param1_value = 0.00;
float param3_value = 0.00;
float param4_value = 0.00;


void setup()
{
 int eeAddress = 0;
 
 // put your setup code here, to run once:
EEPROM.get(0, param1_pulses);
EEPROM.get(4, param2_pulses);
EEPROM.get(8, param3_pulses);
EEPROM.get(12, param4_pulses);

param1_value = processencoder(MIN, MAX, param1_pulses);
// Do something, call Aida DSP API
param2_index = selectorwithencoder(param2_pulses, 2); 
switch(param2_index) 
     {
       case 1:
         // Do something, call Aida DSP API
         break;
       case 2:
         // Do something, call Aida DSP API
         break;
       case 3:
         // Do something, call Aida DSP API
         break;
       case 4:
         // Do something, call Aida DSP API
         break;
     }
param3_value = processencoder(MIN, MAX, param3_pulses);
// Do something, call Aida DSP API

param4_value = processencoder(MIN, MAX, param4_pulses);
     // Do something, call Aida DSP API

 // I/O
 pinMode(PIN_LED, OUTPUT);
 pinMode (SAVE, INPUT);
 pinMode(6, OUTPUT);
 digitalWrite(6,HIGH);

  
 // open the USBSerial port
 Serial.begin(115200);
 clearAndHome();
 Serial.println(F("Aida DSP control with ARDUINO")); // Welcome message
 Serial.println(F("0x00"));    // Print DSP I2C address

 InitAida(); // Initialize DSP board 
 // ... download of program ... (see other examples to know what to do here)
 spettacolino();
}

void loop()
{
  // put your main code here, to run repeatedly:

  if(digitalRead(SAVE)==LOW)  
  {
    digitalWrite(PIN_LED, HIGH);
    delay(50);  // debounce
   // EEPROM.put(0, param1_pulses);
    //EEPROM.put(4, param2_pulses);
    //EEPROM.put(8, param3_pulses);
    //EEPROM.put(12, param4_pulses);
  }
//lcd.clear();
/*delay(100);
   lcd.begin(8, 2);
   lcd.setCursor(0, 0);
   lcd.print(param1_pulses);
lcd.setCursor(0,1);
      lcd.print(param2_pulses);
      */
      
      

  if(digitalRead(ENC_PUSH)==LOW)  
  {
    digitalWrite(PIN_LED, HIGH);
    delay(50);  // debounce
    if(digitalRead(ENC_PUSH)==LOW)
    {
      push_e_count++;
    }   
  }
  else
  {
    if(push_e_count>0 && push_e_count<10)
      push_e_function = 1;
    else if(push_e_count>10 && push_e_count<30)
      push_e_function = 2;
    else
      push_e_function = 0;  // No function triggered on switch
    push_e_count = 0;
    digitalWrite(PIN_LED, LOW);
  }
  
  if(push_e_function==1)
  {
    func_counter--;
    if(func_counter==255)
      func_counter=3;
  }
  else if(push_e_function==2)
  {
    bypass ^=1; 
  }

  timec = millis();
  if(timec-prevtimec >= 1000)  // Here we manage control interface every second
  { 
    clearAndHome();    // !!!Warning use with real terminal emulation program
    Serial.println(F("********************************"));
    Serial.println(F("*    User control interface    *"));
    Serial.println(F("*    AIDA Template2 Sketch     *"));
    Serial.println(F("********************************"));
    Serial.println(F(""));
    Serial.print(F(" Encoder pulses: "));
    Serial.println(getPulses(), DEC);
    Serial.println(F(""));

      Serial.println("param1_pulses=");
      Serial.println(param1_pulses);

      Serial.println("param2_pulses=");
      Serial.println(param2_pulses);

      Serial.println("param3_pulses=");
      Serial.println(param3_pulses);

      Serial.println("param4_pulses=");
      Serial.println(param4_pulses);
    
    if(oldbypass != bypass)
    {
      if(bypass == ON)
      {
        // Do something, call Aida DSP API
      }
      else
      {
        // Do something, call Aida DSP API
      }
      oldbypass = bypass;
    }

    if(old_func_counter != func_counter)
    {
      restore = 1;
      old_func_counter = func_counter;
    }
    switch(func_counter)
    {
    case 0: // PARAM1
    restore=1;
      if(restore)
      {
        restore = 0;
        setPulses(param1_pulses);
      }
      param1_pulses = getPulses();
      param1_value = processencoder(MIN, MAX, param1_pulses);
      // Do something, call Aida DSP API
      break;
    case 1: // PARAM2
    restore=1;
      if(restore)
      {
        restore = 0;
        setPulses(param2_pulses);
      }
      param2_pulses = getPulses();
      param2_index = selectorwithencoder(param2_pulses, 2); 
      switch(param2_index) 
      {
        case 1:
          // Do something, call Aida DSP API
          break;
        case 2:
          // Do something, call Aida DSP API
          break;
        case 3:
          // Do something, call Aida DSP API
          break;
        case 4:
          // Do something, call Aida DSP API
          break;
      }
      break;
    case 2: // PARAM3
    restore=1;
      if(restore)
      {
        restore = 0;
        setPulses(param3_pulses);
      }
      param3_pulses = getPulses();
      param3_value = processencoder(MIN, MAX, param3_pulses);
      // Do something, call Aida DSP API
      break;
    case 3: // Color
    restore=1;
      if(restore)
      {
        restore = 0;
        setPulses(param4_pulses);
      }
      param4_pulses = getPulses();
      param4_value = processencoder(MIN, MAX, param4_pulses);
      // Do something, call Aida DSP API
      break;
    } // End switch func_counter

    // Display information for user
    print_menu_putty();

    prevtimec = timec;
  } // End if 1000ms tick
} // End void loop

void spettacolino()
{
  byte i;
  byte status = 0x00;

  for(i=0;i<6;i++)
  {
    status ^= 1;
    digitalWrite(PIN_LED, status);
    delay(250);
  }
}

void clearAndHome(void)
{
  Serial.write(0x1b); // ESC
  Serial.print(F("[2J")); // clear screen
  Serial.write(0x1b); // ESC
  Serial.print(F("[H")); // cursor to home
}

void print_menu_putty(void)
{
  // Print menu
  Serial.print(F(" Effect status: "));
  if(bypass)
    Serial.println(F("bypass"));
  else
    Serial.println(F("on"));
  Serial.println(F(""));  
  if(func_counter==0)
    Serial.print(F("    "));
  Serial.print(F(" Param 1: "));
  Serial.print(param1_value, 1);
  Serial.println(F(""));
  if(func_counter==1)
    Serial.print(F("    "));
  Serial.print(F(" Param 2: "));
  if(param2_index==1)
    Serial.println(F("one"));
  if(param2_index==2)
    Serial.println(F("two"));
  if(param2_index==3)
    Serial.println(F("three"));
  if(param2_index==4)
    Serial.println(F("four"));
  if(func_counter==2)
    Serial.print(F("    "));
  Serial.print(F(" Param 3: "));
  Serial.print(param3_value, 1);
  Serial.println(F(""));
  if(func_counter==3)
    Serial.print(F("    "));
  Serial.print(F(" Param 4: "));
  Serial.print(param4_value, 1);
  Serial.println(F(""));
  Serial.println(F(""));
  Serial.print(F(" Active item: "));
  Serial.println(func_counter, DEC);
}

That sort of works! I had to remove restore = 1 anyway as with it, it resets the pulse count on each loop, which makes it impossible to do anything!

However, without restore = 1 in switch case 0, param1_value is not restored. I can revert back to setPulses(EEPROM.get(0, param1_pulses)); in setup and this seems to make everything work, as far as I can tell. Do you think there's anything to be wary of in doing this? I'm thinking there must be a reason param1 doesn't restore and this might just be covering up another problem?

(I have another issue/question relating to this sketch that I'd like to ask (namely, how to stop counting pulses when it reaches a certain pulse count), care to help me here or should I start a new thread do you think?)

Many thanks for all your help, most unexpected.

(I have another issue/question relating to this sketch that I'd like to ask (namely, how to stop counting pulses when it reaches a certain pulse count), care to help me here or should I start a new thread do you think?)

There is a lot of code in the library AidaDSP.cpp dealing with pulse counts. Ther may be MAX MIN values but i have not studied it in detail. I think that you must be a musician rather than a C++ coder, but you might want to have a go at changing the library parameters to do what you want.

Without getting into the library you might try something simple in the loop like

if(getPulses() >= xxx);
  setPulses(xxx);

It won't really stop counting, but you can manage the value.

If this doesn't get you where you want to be, I would start a new thread, as you are really beyond the eeprom problems of the original title.

You might try put it in the Audio section of the format as that might get some eyes on it that are familiar with AidaDSP.

Good Luck.

That works just fine. Thanks again, really appreciate it.