Wednesday, December 11, 2013

The final implementation and testing will occur tomorrow.
The IR code and Servo code has been put into the same sketch, but the part missing from the code at this point is the frequency of the IR transmitter that is being used and the way to interpret a high or low signal from a button, i.e. channel up/down. The code could view these as two separate buttons.

The two servos have had their potentiometers glued roughly in the middle of each range, and the two approximate mid-values for each have been noted. This allows for the servo.write function to write a speed to the servo rather than an angle (position).

/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
//IR code:
#include <IRremote.h>
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

//Servo Code
#include <Servo.h>
Servo servoA;
Servo servoB;
const int servospeedA = 81 /*Check value */; //roughly mid value in 0-180 should be no motion
const int servospeedB = 86 /*Check value */; //roughly mid value in 0-180 should be no motion

void setup()
{
  Serial.begin(9600);
//Servo Code:
servoA.attach(9);
servoB.attach(10);
servoA.write(servospeedA);
servoB.write(servospeedB);

//IR Code:
  irrecv.enableIRIn(); // Start the receiver
}//end void setup

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
//Servo code:
if("(channel up) IR value is max"){
  servoA.write(180);
}//end if statement
if("(channel down) IR value is min"){
  servoA.write(0);
}//end if statement
 else(servoA.write(81));
 /* if statements controlling the motorspeeds need specifics on how to obtain high or low
 (up or down channel or volume signal) in order to write forward or backward speed to servo
 correctly. */

if("(volume up) IR value is max"){
  servoB.write(180);
}//end if statement
if("(volume down) IR value is min"){
  servoB.write(0);
}//end if statement
 else(servoB.write(86));
 
}//end void loop

No comments:

Post a Comment