#include "mbed.h" #include "ReceiverIR.h" #include "Servo.h" Servo myservo(p21); ReceiverIR ir_rx(p18); void openBlinds(); void closeBlinds(); int main() { RemoteIR::Format format; //declare data structure for receiving codes uint8_t buf[4]; //declare buffer for storing received code while(1) { if(ir_rx.getState() == ReceiverIR::Received) { ir_rx.getData(&format, buf, sizeof(buf) * 8); //printf("data: %.2x%.2x%.2x%.2x\n",buf[0],buf[1],buf[2],buf[3]); //print entire code for debugging if(format==5) { //check for Sony format (used when code sent from Arduino) if(buf[0]==0x55 && buf[1]==0x05) { //check if command code is correct openBlinds(); } if(buf[0]==0xff && buf[1]==0x0f) { closeBlinds(); } } } } } void openBlinds() { Servo myservo(p21); myservo.calibrate(.0005,270); float p = myservo; while(p <=1) { //open blinds slowly p+=0.01; myservo = p; wait(0.01); } wait(2); DigitalIn servo(p21); //change pin device type to turn off servo } void closeBlinds() { Servo myservo(p21); myservo.calibrate(.0005,270); float p = myservo; while(p>=0) { //open blinds slowly p-=0.01; myservo=p; wait(0.01); } wait(1); DigitalIn servo(p21); //change pin device type to turn off servo } //open 550542bd //close ff0f42bd