i’m working on raspberripi with Wiringpi lib to rotate a servo motor. I receive this error:
src/testApp.cpp: In function ‘void keyPressed(int)’:
src/testApp.cpp:27:3: error: ‘position’ was not declared in this scope
make[1]: *** [obj/linux64/Release/src/testApp.o] Errore 1
make: *** [Release] Errore 2
This error shouldn’t happens in my opinion : i declared a variable int position in testApp.h and assigned a value in testApp.cpp under setup(), in the keypressed() decementing or incrementing it:
//testApp.h
#pragma once
#include "ofMain.h"
#include "wiringPi.h"
#include "softPwm.h"
//#include "pthread.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
//void keyReleased(int key);
//void mouseMoved(int x, int y);
//void mouseDragged(int x, int y, int button);
//void mousePressed(int x, int y, int button);
//void mouseReleased(int x, int y, int button);
//void windowResized(int w, int h);
//void dragEvent(ofDragInfo dragInfo);
//void gotMessage(ofMessage msg);
int position;
};
//testApp.cpp
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
if(wiringPiSetup() == -1){
printf("Error on wiringPi setup\n");}
pinMode (0, OUTPUT) ;
digitalWrite (0, LOW) ;
softPwmCreate(0,0,200);
position = 187;
}
//--------------------------------------------------------------
void testApp::update(){
}
//--------------------------------------------------------------
void testApp::draw(){
ofBackground(ofColor(0,0,0));
ofDrawBitmapString("position:", position,0,20);
}
void keyPressed(int key){
switch (key){
case 'a':
position --;
if(position < 180) position = 180;
softPwmWrite(0, position);
break;
case 'd':
position ++;
if(position > 194) position = 194;
softPwmWrite(0, position);
break;
}
}