I’m trying to make a program which takes a Joystick input from the application shield and returns a rgb output. Here is the code:
#include “mbed.h”
DigitalIn up(A2);
DigitalIn down(A3);
DigitalIn left(A4);
DigitalIn right(A5);
DigitalIn fire(D4);
class Joystick
{
private:
DigitalIn up, down, left, right, fire;
public:
Joystick(PinName u, PinName d, PinName l, PinName r, PinName f);
bool upPressed(void)
{
if(up==1) {
return true;
} else
return false;
}
bool downPressed(void)
{
if(down==1) {
return true;
} else
return false;
}
bool leftPressed(void)
{
if(left==1) {
return true;
} else
return false;
}
bool rightPressed(void)
{
if(right==1) {
return true;
} else
return false;
}
bool firePressed(void)
{
if(fire==1) {
return true;
} else
return false;
}
};
class LED
{
protected:
DigitalOut outputSignal;
bool status;
public:
LED(PinName pin) : outputSignal(pin)
{
off();
}
void on(void)
{
outputSignal = 0;
status = true;
}
void off(void)
{
outputSignal = 1;
status = false;
}
bool getStatus(void)
{
return status;
}
};
int main()
{
Joystick joystick1(A2, A3, A4, A5, D4);
LED redLED(D5);
LED greenLED(D9);
LED blueLED(D8);
LED yellowLED(D5, D9);
LED whiteLED(D5, D9, D8);
while(1) {
if(joystick1.upPressed()==true) {
redLED.on();
} else if(joystick1.downPressed()==true) {
greenLED.on();
} else if(joystick1.leftPressed()==true) {
blueLED.on();
}
else if(joystick1.rightPressed()==true){
yellowLED.on();
}
else if(joystick1.firePressed()==true){
whiteLED.on();
}
}
}
What’s wrong with my code?
Thanks