is it possible to "repair" a code? upon doing a project for college i had to download the libraries and upload that code onto the board. in doing so, multiple errors arose such as:
void setup() {
setupIO();
dsp.ccp:3:21: error: Arduino.h: no such file or directory dsp.ccp: in function 'void setupIO() ' : dsp.ccp: 8: error: 'analogWrite' was not declared in this scope dsp.ccp:16: error: 'INTERNAL' was not declared in this scope [/i][/i]
etc.
perhaps i am uploading the libraries incorrectly? i am using both the Arduino 1.0.3 program and the Arduino 0020 program for the code as the author of the project suggested an older program might work better. It hasn't changed anything
As the code is for the actual project surely it should work no problem?
oh sorry here it is there are multiple bits of code for the whole thing which are broken up into separate files, i thought that the whole thing would have been in one file? ...
#include "dsp.h"
// create an array for the delay
byte array[2000];
//define variables
int j;
int fx;
int mode;
int value50;
int value300;
int value10000;
int delayed;
void setup() {
setupIO();
//set initial values
j = 50;
value50 = 50;
value300 = 300;
value10000 = 1000;
delayed = 0;
}
void loop() {
//check status of the effect potentiometer and rotary switch
readKnobs();
// *************
// ***bitcrush**
// *************
if(mode == 6){
value300 = 1 + ((float) fx / (float) 3);
if(delayed > value300) {
byte input = analogRead(left);
input = (input >> 6 << 6);
output(left, input);
delayed = 0;
}
delayed++;
}
// ***************
// ***Overdrive***
// ***************
if(mode == 7){
value50 = 1 + ((float) fx / (float) 20);
byte input = analogRead(left);
input = (input * value50);
output(left, input);
}
// *************************
// ***short crunchy delay***
// *************************
if(mode == 9){
for(int i = 0; i < 2000; i ++) { // set up a loop
//array[i] = array[i] + array[i - 1]; //removes noise and some delay
output(left, array[i]);
array[i] = analogRead(left);
}
}
// **********************
// ***clean helicopter***
// **********************
if(mode == 10){
value10000 = fx * 10;
if(delayed > value10000) {
for(int i = 0; i < 2000; i ++) { // set up a loop
array[i] = array[i] + array[i - 1]; //removes noise and delay
output(left, array[i]);
array[i] = analogRead(left);
}
delayed = 0;
}
delayed++;
}
// ********************
// ***ring modulator***
// ********************
if(mode == 11){
value50 = 1 + ((float) fx / (float) 20);
byte input = analogRead(left);
input = (input * j);
output(left, input);
j = j - 1;
if (j <= 0) {
j = value50;
}
}
// ************************
// ***YOUR AWESOME SOUND***
// ************************
if(mode == 12){
//************************************
//insert your awesome effect code here
//************************************
}
}
void readKnobs(){
//read the rotary switch
//and determine which effect is selected
//dividing by 75 ensures proper discrete values
//for if statements above
mode = analogRead(2);
mode = mode / 75;
//reads the effects pot to adjust
//the intensity of the effects above
fx = analogRead(3);
}
#include "dsp.h"
#include "timers.h"
#include "WProgram.h"
void setupIO() {
// prepare left
waveformGenerationMode(3, fastPWM);
timerPrescale(3, 1);
analogWrite(3, 0);
// prepare right
waveformGenerationMode(5, fastPWM);
timerPrescale(5, 1);
analogWrite(5, 0);
// faster input
analogReference(INTERNAL);
analogPrescale(analogPrescale32);
}
void output(int channel, short value) {
if(channel == left) {
pwm3 = value >> 2;
pwm11 = (value & B11) << 6;
} else if(channel == right) {
pwm5 = value >> 2;
pwm6 = (value & B11) << 6;
}
}
#define left 0
#define right 1
void setupIO();
void output(int channel, short value);
#include "timers.h"
#include "WConstants.h"
int getTimer(int pin) {
switch(pin) {
case 5: case 6: return 0;
case 9: case 10: return 1;
}
return 2; // 3, 11
}
int getChannel(int pin) {
switch(pin) {
case 6: case 10: case 11: return 0;
}
return 1; // 3, 9, 5
}
// - - -- timer settings
void waveformGenerationMode(int pin, int type) {
int timer = getTimer(pin);
int wgm = type == phaseCorrect ? B001 : B011;
if(timer == 0) {
TCCR0B &= ~(B1 << 3); // clear WGM02
TCCR0A &= ~B11; // clear WGM01 and WGM00
TCCR0A |= wgm; // set WGM01 and WGM00
} else if(timer == 2) {
TCCR2B &= ~(B1 << 3); // clear WGM23
TCCR2A &= ~B11; // clear WGM21 and WGM20
TCCR2A |= wgm; // set WGM21 and WGM20
}
}
void waveformGenerationMode(int pin, int type, int bits) {
int timer = getTimer(pin);
if(timer == 1) {
TCCR1B &= ~(B11 << 3); // clear WGM13 and WGM12
TCCR1A &= ~B11; // clear WGM11 and WGM10
TCCR1B |= (type << 3); // set WGM12
TCCR1A |= (bits - 7);
}
}
void timerPrescale(int pin, int prescale) {
int timer = getTimer(pin);
if(timer == 0) {
TCCR0B &= ~B111; // clear CS02 CS01 CS00
TCCR0B |= getPrescale01(prescale);
} else if(timer == 1) {
TCCR1B &= ~B111; // clear CS12 CS11 CS10
TCCR1B |= getPrescale01(prescale);
} else if(timer == 2) {
TCCR2B &= ~B111; // clear CS22 CS21 CS20
TCCR2B |= getPrescale2(prescale);
}
}
int getPrescale01(int prescale) {
switch(prescale) {
case 1: return B001;
case 8: return B010;
case 64: return B011;
case 256: return B100;
case 1024: return B101;
default: return B000;
}
}
int getPrescale2(int prescale) {
switch(prescale) {
case 1: return B001;
case 8: return B010;
case 32: return B011;
case 64: return B100;
case 128: return B101;
case 256: return B110;
case 1024: return B111;
default: return B000;
}
}
// - - -- analog prescaling
void analogPrescale(int divisionFactor) {
ADCSRA &= ~B111; // clear analog prescale
ADCSRA |= divisionFactor;
}
the chip is a ATMEGA328 and i changed the code you indicated to the correct value, also instead of using the code on the 1.0.3 version, i just downloaded and switched to the earlier version of 0020. i just uploaded the code there and it is working perfectly so far. Thanks a million for your help i really appreciate it!
That's the key. That array is far to big for a 328-based Arduino. If you ever actually fill it, you'll have all kinds of unpredicatable behavior that will drive you crazy.
i am only new to the whole programming idea, but when you mention using a reasonable array size what do you refer to? on different IDE programs is there certain array sizes to suit the program or even a limit for such?
on different IDE programs is there certain array sizes to suit the program or even a limit for such?
The IDE used to program the Arduino has nothing to do with the physical limitations of the Arduino.
Each Arduino model has a set amount of memory, of three different kinds - flash, where the code goes, SRAM where variables, stack, heap, etc. go, and EEPROM where you can persist data between power cycles.
The 328-based Arduinos have 2048 bytes of SRAM. All of your variables, the stack, and the heap need to fit in that space.
A size 2000 shoe is not a reasonable size, considering the size 2048 closet it needs to fit in, along with all the other clothes.
ah ok i think i'm getting the jist! so if i were to try and limit the code to fit at a reasonable size to the SRAM so that its not overloaded, how could i go about doing that?
ah ok i think i'm getting the jist! so if i were to try and limit the code to fit at a reasonable size to the SRAM so that its not overloaded, how could i go about doing that?
There are various methods for determining the amount of free memory available on the forum. Find one. Measure the amount of free memory when setup() runs. Don't use more than about 90% of memory.