/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
#include <Arduino.h>
#define IR_INPUT_PIN 3
#define IR_INPUT_PIN 4
#define IR_INPUT_PIN_3 13
#define IR_RECEIVE_PIN 8
#define IR_BUTTON_2 24
#define IR_BUTTON_PLAY_PAUSE 64
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
const unsigned int RED = A5;
const unsigned int FWD = 10;
int S_FWD;
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL) || defined(ARDUINO_attiny3217)
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
#endif
// Just to know which program is running on my Arduino
#if defined(EICRA) && defined(EIFR) && defined(EIMSK)
// enable interrupt on pin3 on both edges for ATmega328
EICRA |= _BV(ISC10);
// clear interrupt bit
EIFR |= 1 << INTF1;
// enable interrupt on next change
EIMSK |= 1 << INT1;
#else
attachInterrupt(digitalPinToInterrupt(IR_INPUT_PIN), measureTimingISR, CHANGE);
#endif
Serial.println(F("Ready to analyze NEC IR signal at pin " STR(IR_INPUT_PIN)));
Serial.println();
pinMode(13, OUTPUT);
Serial.begin(115200);
sleep();
}
uint8_t ISREdgeCounter = 0;
volatile uint32_t LastMicros;
struct timingStruct
{
uint16_t minimum;
uint8_t indexOfMinimum;
uint16_t maximum;
uint8_t indexOfMaximum;
uint16_t average;
uint16_t SumForAverage;
uint8_t SampleCount;
// uint8_t LastPrintedCount;
};
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
S_FWD = digitalRead(FWD);
if (S_MDO == HIGH){
digitalWrite(13, LOW); // The door is opened, GREEN:ON, others lights turn OFF
digitalWrite(13, HIGH);
}
void Sleep()
{ // Set ALL stack lights OFF
digitalWrite(RED, HIGH);
}
void A_Flashing(){
// AMBER:OFF
digitalWrite(13, HIGH);
delay (50);
// AMBER:ON
digitalWrite(13, HIGH);
delay (50);
}
void R_Flashing(){
digitalWrite(13, HIGH); // RED:OFF
delay (50);
digitalWrite(13, LOW); // RED:ON
delay (50);
}
}