need help with creating a library/class

6 years 3 months ago - 6 years 3 months ago #1157 by alessiow
I've just come across this pedal..I love the idea and concept behind this...I just got an uno and ordered all my parts to put one together.

I'm planning to get at least the printed PCB for this in the near future..Going to breadboard this first to make sure that my idea on creating a pedal can be accomplished...I have the df robot lcd and keypad shield for uno. I have it up and running and over the last few days have played with the code and have a basic menu system working to where i can load up 4 effects and be able to use the lcd shield to select which effect to use.

I have read extensively on the fact that only one sketch can be used on uno. I'm working to trying to get 4 effects. (clean, boost, metronome, and tremolo) into the sketch and working...I'm very close..I've had to do a lot of renaming to eliminate duplicate conditions with variable names...The next step I think would be to put each effect into its own library (.h, and.cpp files) in order to function call each effect depending on what is chosen in the menu...

So my question is has anyone done, or can help with putting the above effects into library format? I've tried many times to do this and just cant seem to grasp the concept of what needs to be where..Any help is appreciated.

Great job on what you has been done so far with this pedal shield

Please Log in to join the conversation.

6 years 3 months ago #1158 by Ray

I have read extensively on the fact that only one sketch can be used on uno. I'm working to trying to get 4 effects. (clean, boost, metronome, and tremolo) into the sketch and working...

There is nothing for the UNO but for the DUE we have a small tutorial, you can get the main idea from it:
www.electrosmash.com/forum/software-peda...same-program?lang=en

So my question is has anyone done, or can help with putting the above effects into library format? I've tried many times to do this and just cant seem to grasp the concept of what needs to be where..Any help is appreciated.


I don't understand what do you mean with a library, could you give me some example or case so I can get it :silly: ?
All the best!

Please Log in to join the conversation.

6 years 3 months ago #1160 by alessiow
yes very similar to what the link you posted is doing....This is my code to run LCD button shield:
#include <LiquidCrystal.h>
#define Booster
// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

//States for the menu.
int currentMenuItem = 0;
int lastState = 0;

void setup() {
//Set the characters and column numbers.
lcd.begin(16, 2);
//Print default title.
clearPrintTitle();
Serial.begin(9600);
}

void loop() {
//Call the main menu.
mainMenu();
}

void mainMenu() {
//State = 0 every loop cycle.
int state = 0;
//Refresh the button pressed.
int x = analogRead (0);
//Set the Row 0, Col 0 position.
lcd.setCursor(0,0);

//Check analog values from LCD Keypad Shield
if (x < 100) {
//Right
} else if (x < 200) {
//Up
state = 1;
} else if (x < 400){
//Down
state = 2;
} else if (x < 600){
//Left
} else if (x < 800){
//Select
state = 3;
}

//If we are out of bounds on th menu then reset it.
if (currentMenuItem < 0 || currentMenuItem > 4) {
currentMenuItem = 0;
}

//If we have changed Index, saves re-draws.
if (state != lastState) {
if (state == 1) {
//If Up
currentMenuItem = currentMenuItem - 1;
displayMenu(currentMenuItem);
} else if (state == 2) {
//If Down
currentMenuItem = currentMenuItem + 1;
displayMenu(currentMenuItem);
} else if (state == 3) {
//If Selected
selectMenu(currentMenuItem);
}
//Save the last State to compare.
lastState = state;
}
//Small delay
delay(5);
}

//Display Menu Option based on Index.
void displayMenu(int x) {
switch (x) {
case 1:
clearPrintTitle();
lcd.print ("->Booster Effect");
break;
case 2:
clearPrintTitle();
lcd.print ("->Clean Effect");
break;
case 3:
clearPrintTitle();
lcd.print ("->Metronome");
break;
case 4:
clearPrintTitle();
lcd.print ("->Tremolo Effect");
break;
}
}

//Print a basic header on Row 1.
void clearPrintTitle() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("MegaEffect Pedal ");
lcd.setCursor(0,1);
}

//Show the selection on Screen.
void selectMenu(int x) {
switch (x) {
case 1:
clearPrintTitle();
lcd.print ("U Chose Booster");
//Call the function that belongs to Option 1
void Booster(); // Issues with this line here<
Serial.println("Running Booster");
break;
case 2:
clearPrintTitle();
lcd.print ("U Chose Clean");
//Call the function that belongs to Option 2
Serial.println("Running Clean");
break;
case 3:
clearPrintTitle();
lcd.print ("U Chose Metronome");
//Call the function that belongs to Option 3
Serial.println("Running Metronome");
break;
case 4:
clearPrintTitle();
lcd.print ("U Chose Tremolo");
//Call the function that belongs to Option 4
Serial.println("Running Tremolo");
break;
}
}

Then on tabs in same sketch I have the four effects. i'm using the AudioDsp.ino files for the effects. The above code works....But i dont know how to call in the AudioDsp.ino effect files....Cant seem to figure it out....I know that i need to make changes to variables and there is currently some Pin conflicts that need addressing...This is the code i have for Booster:
/*

pedalShieldUno/AudioDSP/booster
Alternate implementation of the pedalshield_uno_booster effect.

- reads the ADC and plays it into the PWM output.
- pressing the pushbutton_1 or 2 turns the volume up or down.

For info and circuit diagrams see github.com/tardate/LittleArduinoProjects...Uno/AudioDSP/booster

*/

#include <AudioDspDriver.h> // main AudioDSP controller class

AudioDspDriver dsp_driver;

void setup1() {
dsp_driver.init();
}

void loop1() {
dsp_driver.process_controls();
}

/* transformer
* the input signal is 16 bit signed (values from -32768 to +32767, INT16_MIN to INT16_MAX)
* pb_level is 0-1024 with midpoint 512
*/
int16_t transformer(int16_t input, int pb_level) {

int16_t volume = map(pb_level, 0, 1024, 0, INT16_MAX);
return map(input, INT16_MIN, INT16_MAX, -volume, volume);

}

/* Timer 1 interrupt service routine
* Perform audio input/processing/output here
*/
ISR(TIMER1_CAPT_vect) {
dsp_driver.transform(&transformer);
}

Granted there are two library files for the AudioDsp I haven't included here..if you need them follow link at to of booster file. I appreciate your help. I know I need to change some pin call outs to eliminated conflicts and want to try to keep the changes to the Effect files and not change the LCD button shield just yet as it currently sits on top of uno..I need to figure out how to tie the Lcd shield into the pedalshield....Still waiting on my parts order to show up that got lost in delivery and company sent out another order...then i can build my pedal shield on bread board to get it running...

Please Log in to join the conversation.

6 years 3 months ago #1167 by Ray
looks like an interesting idea, the work made by Paul Gallagher was fantastic (github.com/tardate/LittleArduinoProjects...alShieldUno/AudioDSP).
We also have all the codes uploaded to github (github.com/electrosmash)
The following user(s) said Thank You: Frostbite

Please Log in to join the conversation.

6 years 3 months ago #1170 by alessiow
yes it does. That was where some of the code came from...I had the idea to do something similar when i first came across your pedal shield.. I looked over and found his idea after posting this thread. I loved that he had done his in a library format...that should help tremendously to implement the code in what I'm trying to do with your code for the pedalshield
The following user(s) said Thank You: Ray

Please Log in to join the conversation.

6 years 3 months ago #1174 by alessiow
Ok...So last night I sat down and did up a pin comparison between the pedalShield and my LCD Keypad Shield..I have a few conflicts..
PWM_10 shared
PWM_9 shared
A0 shared
All others seem to be good. You all know the pedalShield pins...so these are my LCD shield minus the above conflicts:
RX = GND
D4-D7 are DB4-DB7 : used as high order bidirection bus pins, for data transfer and receive between MCU and LCD
D-8 = RS : Choose Data or Signal Display
D-9 = Enable : Start data read/write
D-10 = LCD Backlight Control

I'm can't alter the LCD shield. So now my question is can I safely move:
A0 on pedalShield to A1
PWM_10 on pedalShield to D-11
PWM_9 on pedalShield to D-3
This would eliminate all pin conflicts...Software would obviously need to be adjusted to move Pin calls. These changes should work, I'm just unsure if the PWM pins need to be side by side. If they do then this project idea on an Arduino UNO is stopped dead in its tracks.

Please Log in to join the conversation.

6 years 3 months ago #1175 by Ray

I'm can't alter the LCD shield. So now my question is can I safely move:
A0 on pedalShield to A1
PWM_10 on pedalShield to D-11
PWM_9 on pedalShield to D-3


You could probably move A0 to A1 without many problems, but the PWM pins would be more difficult:
If you have a look at this image ( www.pighixxx.com/test/wp-content/uploads/2017/05/uno.png ) you can see that PW9 and PW10 signals are OC1A and OC1B, you may use OC0A and OC0B pins (PWM5 and 6) BUT the software changes to do it is not trivial, I never tried it I am not sure if I can give you support on that.
So in a nutshell, it could be possible but new software needs to be written.
The following user(s) said Thank You: alessiow

Please Log in to join the conversation.

6 years 3 months ago - 6 years 3 months ago #1176 by alessiow
so it sounds as if this is dead in the water on uno then...Id need to use 0c2b and could possibly use 0c1b or 0c2a...those would get rid of all pin conflicts... but as you say software would need to be rewritten....could you point me at which software you are refering to...

Edit...
I just found this info oscarliang.com/arduino-timer-and-interrupt-tutorial/...
he basically says that the pins i was hoping to use :
The Arduino has 3 timers and 6 PWM output pins. The relation between timers and PWM outputs is:

Pins 5 and 6: controlled by Timer0
Pins 9 and 10: controlled by Timer1
Pins 11 and 3: controlled by Timer2.....<

So i need to get into the software and change the pins and timers to Timer2 and all should be good with trying to get this going on uno...I did just order a mega 2560 so that may help even more...

Please Log in to join the conversation.

6 years 3 months ago #1180 by Ray

So i need to get into the software and change the pins and timers to Timer2 and all should be good with trying to get this going on uno...I did just order a mega 2560 so that may help even more...


Some software work is needed to change timers from Timer 1 to Timer 2.
The Mega could bring you new possibilities, I may order some and check what advantages do they have...

Please Log in to join the conversation.

6 years 3 months ago #1183 by alessiow
Ok..so time for update...I looked into the datasheets on the uno...The current timer is a 16-bit timer that the pedalshield is using...the other two timers are only 8-bit. So the idea on moving to pins 5-6 or 3-11 are not gonna work. I'm now looking to try and move the Lcd keypad shield around and use pins that won't conflict..
The biggest thing i see so far in the mega datasheets is that it has way more i/o's than the uno. way more pwm pins, more timers, bigger ram, just better all around that the uno. alot of shields are supposed to be compatible with the mega and the uno as far as pins go as well.. here is a quick run down on the uno and mega:
Uno
1. Microcontroller core: AVRmega328P-PU ( Processing speed 20MIPS)
2. Working voltage: +5V
3. External input voltage:+7V~+12V(suggest)
4. External input voltage ( extremum ): +6V≤ Vin ≤ +20V
5. Digital signal I/O interface: 14 ( 6 PWM input interface)
6. Analog signal input interface: 6
7. DC I/O interface current: 40mA
8. Flash capacity: 32KB( other 2k used in hootloader)
9. SRAM: 2KB
10. EEPROM: 1kb
11. Clock Speed:16 MHZ

Mega:
Microcontroller: ATmega2560
Operating Voltage: 5V
Input Voltage (recommended):7-12V
Input Voltage (limits): 6-20V
Digital I/O Pins: 54 (of which 15 provide PWM output)
Analog Input Pins: 16
DC Current per I/O Pin: 40 mA
DC Current for 3.3V Pin: 50 mA
Flash Memory: 256 KB of which 8 KB used by bootloader
SRAM: 8 KB
EEPROM: 4 KB
Clock Speed: 16 MHz

I finally found the full datasheet for the mega. so i'm going to sit down tonight and go thru it. I would love to help make a Mega version of this pedalshield a reality. Especially if we could use the LCD keypad shield with it having a menu system to be able to scroll thru and select the effect we want to use versus having to upload each effect every time...there is sufficient space on both the uno and mega to combine the sketches into one file,but it a matter of getting it written correctly in one file..I think others would jump on this if it could be done.
The following user(s) said Thank You: Ray

Please Log in to join the conversation.

Time to create page: 0.102 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio