Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not defined in this scope- arduino.mk on debian wheezy ARMv5 #286

Closed
monkmandolins opened this issue Nov 5, 2014 · 5 comments
Closed

Not defined in this scope- arduino.mk on debian wheezy ARMv5 #286

monkmandolins opened this issue Nov 5, 2014 · 5 comments
Labels

Comments

@monkmandolins
Copy link

Hi Sudar-
I am having trouble with the arduino.mk compiling a sketch. I am sure the solution is obvious, but I would really appreciate your help. I have set this up on a Pogoplug V4 which runs an ARMv5 Marvell Kirkwood.
Linux version 3.14.0-kirkwood-tld-1 (root@tldDebian) (gcc version 4.6.3 (Debian 4.6.3-14))

Here is the sketch:

int rPin = 11; // red
int gPin = 10;  // green
int bPin = 9;  // blue
float rValue, gValue, bValue;
float redDifference, blueDifference, greenDifference;
int fadeTime = 10;

void setup()  { } 

void loop()  { 

  // blues and greens
  controlledFade(255,255,0, 0,0,0);  //dark blue to white
  controlledFade(0,0,0, 255,0,255);  //white to intense green
  controlledFade(255,0,255, 0,0,0);  //intense green to white
  controlledFade(0,0,0, 255,255,0);  //white to dark blue
  delay(1000);

}

void controlledFade(int r1,int g1,int b1, int r2,int g2,int b2){
  int red1 = r1;
  int green1 = g1;
  int blue1 = b1;
  int red2 = r2;
  int green2 = g2;
  int blue2 = b2;

  redDifference = 255.0 / (red1 - red2);
  greenDifference = 255.0 / (green1 - green2);
  blueDifference = 255.0 / (blue1 - blue2);

  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue++) { 
    rValue = red1 - fadeValue/redDifference;
    gValue = green1 - fadeValue/greenDifference;
    bValue = blue1 - fadeValue/blueDifference;

    analogWrite(rPin, rValue);
    analogWrite(gPin, gValue);    
    analogWrite(bPin, bValue);
    delay(fadeTime);  
  } 
}

my Makefile is:

ARDUINO_DIR = /usr/share/arduino
BOARD_TAG    = pro5v328
ARDUINO_PORT = /dev/ttyUSB0
ARDUINO_LIBS =
include /usr/share/arduino/Arduino.mk

and the output after '''make''' or '''make upload''' is as follows:

root@debian:/home/arduino# make upload
echo '#include <Arduino.h>' > build-cli/nurserylights.cpp
cat  nurserylights.ino >> build-cli/nurserylights.cpp
/usr/bin/avr-g++ -MM -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/wiring -I/usr/share/arduino/libraries/wiring_pulse -I/usr/share/arduino/libraries/wiring_digital -I/usr/share/arduino/libraries/wiring_shift -I/usr/share/arduino/libraries/wiring_analog -I/usr/share/arduino/libraries/main -I/usr/share/arduino/libraries/WInterrupts -I/root/sketchbook/libraries/wiring -I/root/sketchbook/libraries/wiring_pulse -I/root/sketchbook/libraries/wiring_digital -I/root/sketchbook/libraries/wiring_shift -I/root/sketchbook/libraries/wiring_analog -I/root/sketchbook/libraries/main -I/root/sketchbook/libraries/WInterrupts -g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions build-cli/nurserylights.cpp -MF build-cli/nurserylights.d -MT build-cli/nurserylights.o
cat build-cli/nurserylights.d > build-cli/depends.mk
for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \
          do $STTYF /dev/tty >/dev/null 2>&1 && break ; \
        done ; \
        $STTYF /dev/ttyUSB0  hupcl ; \
        (sleep 0.1 2>/dev/null || sleep 1) ; \
        $STTYF /dev/ttyUSB0 -hupcl 
/usr/bin/avr-g++ -c -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I. -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/wiring -I/usr/share/arduino/libraries/wiring_pulse -I/usr/share/arduino/libraries/wiring_digital -I/usr/share/arduino/libraries/wiring_shift -I/usr/share/arduino/libraries/wiring_analog -I/usr/share/arduino/libraries/main -I/usr/share/arduino/libraries/WInterrupts -I/root/sketchbook/libraries/wiring -I/root/sketchbook/libraries/wiring_pulse -I/root/sketchbook/libraries/wiring_digital -I/root/sketchbook/libraries/wiring_shift -I/root/sketchbook/libraries/wiring_analog -I/root/sketchbook/libraries/main -I/root/sketchbook/libraries/WInterrupts -g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions build-cli/nurserylights.cpp -o build-cli/nurserylights.o
build-cli/nurserylights.cpp: In function 'void loop()':
build-cli/nurserylights.cpp:14:34: error: 'controlledFade' was not declared in this scope
make: *** [build-cli/nurserylights.o] Error 1

Do you have any advice for me? I can't use the GUI arduino IDE on this device.
Thanks
Peter

@peplin
Copy link
Contributor

peplin commented Nov 5, 2014

Hey Peter, try putting your controlledFade function above the loop function where you use it. In C/C++ functions have to be declared before they can be used. The Arduino GUI has some tricks behind the scenes to hide this requirement (if I remember correctly it injects a forward declaration of each function at the top of the file).

@sej7278
Copy link
Collaborator

sej7278 commented Nov 5, 2014

yes as @peplin says, the arduino ide does some fudgery which basically encourages bad c++ coding.

you must always declare functions before using them, so really setup() and loop() should come at the end of the sketch, not the beginning.

if you look at your sketch it makes sense really - you've called controlledFade() from loop() but loop() doesn't know what controlledFade() does, as its further down the file.

@sudar sudar added the wontfix label Nov 5, 2014
@sudar
Copy link
Owner

sudar commented Nov 5, 2014

@monkmandolins See #59 as well.

@monkmandolins
Copy link
Author

That did it, and I am very grateful.
I will now do everything from the command line to close the gap between real C and Arduino.
Thank you!

@sej7278
Copy link
Collaborator

sej7278 commented Nov 5, 2014

great!

@sudar sudar closed this as completed Nov 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants