- CODE: SELECT_ALL_CODE
#include <Shield_PS2.h>
//declare class objects
PS2 ps2=PS2(); //PS2 class object: ps2
const int mtr1_dir = 2;
const int mtr1_pwm = 3;
void setup()
{
ps2.init(9600, 2, 3);
pinMode(mtr1_dir, OUTPUT);
pinMode(mtr1_pwm, OUTPUT);
digitalWrite(mtr1_pwm,LOW);
}
void loop()
{
if( ps2.getval(p_up)==0)
{
digitalWrite(mtr1_dir, LOW);
analogWrite(mtr1_pwm, 255);
delay(100);
}
else if( ps2.getval(p_down)==0)
{
digitalWrite(mtr1_dir, HIGH);
analogWrite(mtr1_pwm, 255);
delay(100);
}
else
{
digitalWrite(mtr1_pwm, LOW);
}
}
When i tested my controller using the sample coding given to light up pin13 LED with the "select" button, it is working. But when i uploaded this coding into my arduino, it doesn't work. The motor just keep turning in one direction without any button pressed. I have tried the rest of the buttons to light up the pin13 LED. All of them are working. It's just doesn't work when it is use to send signal to the MD30C. Anyone know any problem with the coding? Did i left out any library? Thank you