Skip to content

Instantly share code, notes, and snippets.

@henricavalcante
Last active August 29, 2015 14:04
Show Gist options
  • Save henricavalcante/513e688210e1826614ff to your computer and use it in GitHub Desktop.
Save henricavalcante/513e688210e1826614ff to your computer and use it in GitHub Desktop.
ARDUINO Samples
/*
* 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
*/
#define IR_POWER 0xFFA25D
#define IR_MODE 0xFF629D
#define IR_MUTE 0xFFE21D
#define IR_PLAY 0xFF22DD
#define IR_BACKWD 0xFF02FD
#define IR_FORWD 0xFFC23D
#define IR_EQ 0xFFE01F
#define IR_MINUS 0xFFA857
#define IR_PLUS 0xFF629D
#define IR_LOOP 0xFF9867
#define IR_USD 0xFFB04F
#define IR_0 0xFF6897
#define IR_1 0xFF30CF
#define IR_2 0xFF18E7
#define IR_3 0xFF7A85
#define IR_4 0xFF10EF
#define IR_5 0xFF38C7
#define IR_6 0xFF5AA5
#define IR_7 0xFF42BD
#define IR_8 0xFF4AB5
#define IR_9 0xFF52AD
#define IR_HOLD 0xFFFFFFFF
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
// Pin 13 has a LED connected on most Arduino boards.
// give it a name: We will use the + remote button to turn the LED on
// and the - remote button toturn the LED off
int led = 13;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
//Serial.println(results.value);
if (results.value == IR_9){
Serial.println("You pressed button 9");
}
if (results.value == IR_POWER){
Serial.println("You pressed the power button");
}
if (results.value == IR_PLUS){
Serial.println("You pressed the UP button");
}
if (results.value == IR_MINUS){
Serial.println("You pressed the DOWN button");
}
irrecv.resume(); // Receive the next value
}
}
int servoPin = 7; // R/C Servo connected to digital pin
int mySpeed; // angle of the servo (roughly in degrees) 0-180
int pulseWidth; // function variable
void servoPulse(int servoPin, int myAngle) {
pulseWidth = (mySpeed * 11) + 500; // converts angle to microseconds
digitalWrite(servoPin, HIGH); // set servo high
delayMicroseconds(pulseWidth); // wait a very small amount
digitalWrite(servoPin, LOW); // set servo low
delay(20); // refresh cycle of typical servos (20 ms)
}
void setup() {
pinMode(servoPin, OUTPUT); // set servoPin pin as output
}
void loop() {
// cycle through every angle (rotate the servo 180 slowly)
for (mySpeed=110; mySpeed<=118; mySpeed++) {
servoPulse(servoPin, mySpeed);
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment