Skip to content

Instantly share code, notes, and snippets.

#include <TimerOne.h>
#include <Wire.h>
//comment this out to see the demodulated waveform
//it is useful for debugging purpose.
#define MODULATED 1
const int IR_PIN = 3;
const unsigned long DURATION = 180000l;
const int HEADER_DURATION = 2000;
@navillus5
navillus5 / BlinkTwo
Last active December 23, 2015 12:08
Slight modification of the Arduino Blink sketch
/*
BlinkTwo
Turns two LEDs on and off in unison.
The delay times are controlled by two variables
that are defined at the beginning of the program.
This example code is in the public domain.
*/
// Use the LEDs that are connected to I/O pins 12 and 13
@navillus5
navillus5 / BlinkTwoAlternate
Created September 20, 2013 03:23
Another slight variation on the Arduino Blink Example
/*
BlinkTwo
Turns two LEDs on and off in unison.
The delay times are controlled by two variables that are defined at the
beginning of the program.
This example code is in the public domain.
*/
// Use the LEDs that are connected to I/O pins 12 and 13
@navillus5
navillus5 / Knight Rider
Last active April 4, 2017 13:53
Another variation of the Blink program. This introduces the use of the array construct and a For-Loop to simplify the coding.
/*
BlinkArray
Usses and Array structure and For and If loops to create an LED chase effect
This example code is in the public domain.
*/
/* Intialize an array of LED pins
Define a delay called "rate"
@navillus5
navillus5 / PushOnce
Created September 23, 2013 02:54
Simple variation of Arduino Example Program "Button". A simple software debounce is included along with a pushbutton counter that echos back to serial monitor.
/*
PushOnce
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pin 2 is attached to one leg of pushbutton and to +5V through 10k resistor
* other leg uf pushbutton is attached to ground
@navillus5
navillus5 / button with functions
Created September 25, 2013 13:10
Arduino code - Example of how to use a single push-button to cycle through a number of choices. This example code uses functions to: ** debounce the button ** check the state of the button ** keep track of the current selection of the push button (in this case 1, 2, 3, 4, or 5) ** turn on an LED on the board that corresponds to the button select…
/*
Arduino code - Example of how to use a single push-button to cycle through a number of choices. This example code uses functions to:
** debounce the button
** check the state of the button
** keep track of the current selection of the push button (in this case 1, 2, 3, 4, or 5)
** turn on an LED on the board that corresponds to the button selection
** a dummy function is included that can be used to set the condition of some device (motor speed, servo position, etc...) that corresponds to the button choice.
*/
// global variables
void setup(){
//sets pins to OUTPUT
pinMode(11,OUTPUT);pinMode(10,OUTPUT);pinMode(9,OUTPUT);
pinMode(6,OUTPUT);pinMode(5,OUTPUT);pinMode(3,OUTPUT);}
// extern creates global variables
extern float p = 1; // phase shift constant
extern float s = .005; // angular velocity constant
extern float g = 1; // brightness threshold
extern int mode = 0 ; // operation mode
@navillus5
navillus5 / functions2
Last active April 4, 2017 13:43
Arduino Sample Code
/* Shows the use of a user-defined function call from loop().
The sketch also uses a flag variable to keep track of the
current position state of the potentiometer.
The potentiometer is used to provide and analog signal to pin
A0. When the value of the analog read variable potVal goes
from a value that is below 400 to a value that is above
the threshold value of 600 the function lights() is called to
flash the green and red LEDs. The function is not called again
until the pot is again cycle below 400 and then above 600. This
// Define constants
const int buttonPin = 2;
// Define variables
boolean buttonState = HIGH;
// Setup
// Define constants
const int buttonPin = 2;
// Define variables
boolean buttonState = HIGH;
// Setup