Hello,
I'm trying to add code to this template sketch to add EEPROM functionality which will save and restore encoder pulse counts in order to restore user settings on start up.
At the moment, for testing purposes I am just trying to EEPROM.put and EEPROM.get param1_pulses (int32_t) to address 10.
I can successfully write to EEPROM and have verified this using a modified version of the EEPROM.get example but cannot 'assign' the int32_t stored in address 10 to param1_pulses in my sketch. How can I do this please?
Full code pasted below, pertinent bits extracted here:
const int SAVE = 6;
int32_t param1_pulses = 0;
void setup()
{
pinMode(PIN_LED, OUTPUT);
pinMode (SAVE, INPUT);
EEPROM.get(10, param1_pulses);
}
void loop()
{
if(digitalRead(SAVE)==LOW)
{
digitalWrite(PIN_LED, HIGH);
delay(50); // debounce
EEPROM.put(10, param1_pulses);
}
lcd.begin(8, 2);
lcd.print(param1_pulses);
}
Many thanks.
/*
AIDA Template2 Sketch
This sketch is a Template to start coding with
Aida DSP.
This sketch was written for Arduino, and will not work on other boards.
The circuit:
Audio:
* Input range 2.0Vrms (5.66Vpp, 8.23dBu)
* Output range 0.9Vrms (2.5Vpp, 1.30dBu)
PC:
* Please connect with PuTTY on Arduino USB Serial with a PC for a minimal user interface
NOTE:
Attenuation Out/In = 2.264, to have out = in you must provide 7.097dB of gain through DSP algorithm
or externally with active LPF filter.
created November 2014
by Massimo Pennazio
This example code is in the public domain.
*/
#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 = 6;
#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()
{
// put your setup code here, to run once:
// I/O
pinMode(PIN_LED, OUTPUT);
pinMode (SAVE, INPUT);
EEPROM.get(10, param1_pulses);
// 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(10, param1_pulses);
}
lcd.begin(8, 2);
lcd.print(param1_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(""));
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
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
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
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
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);
}