Friday, December 12, 2014

Finalized Arduino Code

The first set of code controls two stepper motors via an infra red remote. One compresses the spring, loading the system. The other adjusts the launch angle for the part. Aaron deciphered the infrared control while Dylan and James fought through the motor coding.
**Libraries are dec
 ------------
 #include <IRremote.h>
  #include <IRremoteInt.h>
#include <IRemote.h>
#include <Stepper.h>
int RECV_PIN = 11; // Remember to add 0x to the hexadecimal codes 
long button1 = 0xAC516266; 
 long button2 = 0xAD5163FB; 
 long button3 = 0xBE15326E;
 ong button4 = 0x9FA96F;
 IRrecv irrecv(RECV_PIN);
 decode_results results;
 const int stepsPerRevolution = 200;
 Stepper s1(200, 8,9,10,11);
 Stepper s2(200, 2,3,4,5);
 void setup() { Serial.begin(9600);
 irrecv.enableIRIn(); // Start the receiver
 irrecv.blink13(true); // blink LED on P13 when IR signal is present
 s1.setSpeed(60);
 s2.setSpeed(60);
 }
 void loop()
{
 if (irrecv.decode(&results))
{ if (results.value == button1)
{ s1.step(200); delay(500);
 }
 if (results.value == button2)
{ s1.step(-200); delay(500); }
 if (results.value == button3)
{ s2.step(200); delay(500); }
 if (results.value == button4)
{ s2.step(-200);
 delay(500); }
 irrecv.resume(); // Receive the next value
 }
 }

 -------------------------------

The code below controls a servo and stepper motor via an IR remote. The servo is used as a lock/trigger mechanism while the stepper motor is used for the rotating base.

 #include  <IRremote.h>
#include  <IRremoteInt.h>
#include <IRremote.h>
#include  <Stepper.h>
#include

int RECV_PIN = 12;  // Remember to add 0x to the hexadecimal codes
 long button1 = 0xAC516266;
 long button1a = 0xE516266;
 long button2 = 0xAD5163FB;
 long button2a =0xAD5163FB;
 long button3 = 0xBE15326E;
 long button3a = 0xDB9D3097;
 long button4 = 0x9FA96F;
 long button4a = 0x9912B99A;
 long button6 = 0x11;
 long button6a = 0x811;
 IRrecv irrecv(RECV_PIN);
 decode_results results;
 const int stepsPerRevolution = 200;
Stepper s1(200, 4,5,6,7);
 Stepper s2(200, 8,9,10,11);
 Servo myservo;
 void setup()
 {
 Serial.begin(9600);
 irrecv.enableIRIn(); // Start the receiver
 irrecv.blink13(true); // blink LED on P13 when IR signal is present
 s1.setSpeed(60);
 s2.setSpeed(60);
 myservo.attach(9);
 }
 void loop()
{ if (irrecv.decode(&results))
{ if (results.value == button1)
{ s1.step(200); delay(100);
 } if (results.value == button1a)
{ s1.step(200); delay(100); }
 if (results.value == button2)
{
 s1.step(-200); delay(100);
 }
 if (results.value == button2a)
{
 s1.step(-200); delay(100);
 }
 if (results.value == button3)
{
 s2.step(200); delay(100);
 }
 if (results.value == button3a)
{
 s2.step(200); delay(100); }
 if (results.value == button4)
{
 s2.step(-200); delay(100); }
 if (results.value == button4a)
{
 s2.step(-200); delay(100);
 }
 if (results.value == button6)
{
 myservo.write(0);
 delay(100);
 }
 if (results.value == button6a)
{
 myservo.write(90);
 delay(100);
 }
 irrecv.resume(); // Receive the next value
 }
 }

No comments:

Post a Comment