Hi,
I’m trying to code in C++ as I don’t really know C. I think I am all mixed up with the libraries with AVR Studio 4. I tried the following code but am getting all kinds of errors. What am I doing wrong? Thanks,
#include <pololu/orangutan>
//#include <OrangutanLEDs.h>
//#include <OrangutanAnalog.h>
//#include <OrangutanMotors.h>
// This is a C++ trial with motors and sensors
//OrangutanAnalog analog;
//OrangutanLEDs leds;
//OrangutanMotors motors;
void loop ()
{
//note the following line could also be accomplished with:
// int pot = analog.read(7);
int pot = analog.readTrimpot(); // determine trimpot position
int motorSpeed = pot/2-256; // turn pot reading into number between -256 and 255
if (motorSpeed == -256)
motorSpeed = -255; // 256 is out of range
motors.setSpeed (motorSpeed, motorSpeed);
int ledDelay = motorSpeed;
if (ledDelay < 0)
ledDelay = -ledDelay; // make delay a non-negative number
ledDelay = 256-ledDelay;
leds.red(HIGH); // turn red LED on
delay(ledDelay);
leds.red(LOW); // turn red LED off
delay(ledDelay);
}
Errors:
Build started 21.3.2012 at 19:03:06
avr-gcc -mmcu=atmega328p -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT test.o -MF dep/test.o.d -c ../test.c
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:1,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanAnalog/OrangutanAnalog.h:57: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'OrangutanAnalog'
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:3,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:28: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'OrangutanTime'
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h: In function 'get_ms':
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:97: error: 'OrangutanTime' undeclared (first use in this function)
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:97: error: (Each undeclared identifier is reported only once
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:97: error: for each function it appears in.)
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:97: error: expected ';' before ':' token
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h: In function 'millis':
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:98: error: 'OrangutanTime' undeclared (first use in this function)
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:98: error: expected ';' before ':' token
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h: In function 'delay':
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:100: error: expected expression before ':' token
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h: In function 'delay_ms':
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:101: error: expected expression before ':' token
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h: In function 'delay_us':
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:102: error: expected expression before ':' token
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h: In function 'delayMicroseconds':
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanTime/OrangutanTime.h:103: error: expected expression before ':' token
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:4,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanMotors/OrangutanMotors.h: At top level:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanMotors/OrangutanMotors.h:29: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'OrangutanMotors'
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:5,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanLCD/OrangutanLCD.h:166: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'OrangutanLCD'
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanLEDs/OrangutanLEDs.h:27,
from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:6,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanLEDs/../OrangutanDigital/OrangutanDigital.h:131: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'OrangutanDigital'
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:6,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanLEDs/OrangutanLEDs.h:47: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'OrangutanLEDs'
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:8,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/PololuQTRSensors/PololuQTRSensors.h:48: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PololuQTRSensors'
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/PololuQTRSensors/PololuQTRSensors.h:167: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PololuQTRSensorsRC'
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/PololuQTRSensors/PololuQTRSensors.h:254: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PololuQTRSensorsAnalog'
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:9,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/PololuWheelEncoders/PololuWheelEncoders.h:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PololuWheelEncoders'
In file included from c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:13,
from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/OrangutanServos/OrangutanServos.h:51: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'OrangutanServos'
In file included from ../test.c:1:
c:/winavr-20100110/lib/gcc/../../avr/include/pololu/orangutan:16:45: error: pololu/OrangutanSVP/OrangutanX2.h: No such file or directory
../test.c: In function 'loop':
../test.c:17: error: 'analog' undeclared (first use in this function)
../test.c:21: error: 'motors' undeclared (first use in this function)
../test.c:28: error: 'leds' undeclared (first use in this function)
make: *** [test.o] Error 1
Build failed with 25 errors and 0 warnings...