Sunteți pe pagina 1din 2

#include <Servo.

h>
Servo myservo; // create servo object to control a servo
#include <IRremote.h>
int ledPIN = 13;
int servoPin = 9;// this pin must be of those with PWM ~
// Pines servo Ir
int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 6
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'

// Pines servo bluetooth


#define CWpin 2 // push button for CW
#define STOPpin 3 // push button pin for STOP
#define CCWpin 4 // push button for CCW

int sc[]={180,85, 0};// servo commands are in order CCW, STOP,CW

String scText[]={"CCW","Stop","CW"};// define texts for 3 action


int statusText;
int CWBS, CCWBS, SBS;
//CW button status (CWBS)
//CCW button status (CCWBS)
//stop button status (SBS)

void setup() {
Serial.begin(9600);
myservo.attach(9);
irrecv.enableIRIn(); // Start the receiver
myservo.write(90);
pinMode(ledPIN,OUTPUT);

pinMode(STOPpin,INPUT_PULLUP);// set pin for push button STOP


pinMode(CCWpin,INPUT_PULLUP);// set pin for push button CCW
pinMode(CWpin,INPUT_PULLUP);// set pin for push button CW

myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object


myservo.write(sc[1]);// send STOP command
statusText=1;// initial value is STOP

void servoCommand(int n)
{
statusText = n;
myservo.write(sc[n]);
Serial.print("Going to ");
Serial.print(scText[n]);
Serial.print( "(");
Serial.print(sc[n]);
Serial.println(")");
}

void loop() {

if (irrecv.decode(&results)) {
irrecv.resume(); // Receive the next value

if (results.value == 0xFF18E7)
{
myservo.write(0);
digitalWrite(ledPIN,HIGH);
}
else if (results.value == 0xFF4AB)
{
myservo.write(180);
digitalWrite(ledPIN,HIGH);
}
else if (results.value == 0xFF38C7)
{
myservo.write(90);
digitalWrite(ledPIN,LOW);
}
} // Fin if irrecv

CCWBS = digitalRead(CCWpin);// read status of button CCW


SBS = digitalRead(STOPpin);// read status of button STOP
CWBS = digitalRead(CWpin);// read status of button CW

if(CCWBS ==LOW)
{
servoCommand(0);
}else if(SBS ==LOW)
{
servoCommand(1);
}else if(CWBS ==LOW)
{
servoCommand(2);
}

Serial.println(scText[statusText]);
delay(50);

S-ar putea să vă placă și