Skip to content

Instantly share code, notes, and snippets.

@navillus5
navillus5 / Timer1 Example B
Last active April 4, 2017 14:01
Arduino Timer1 Example 2
/* This example employs Timer1 to blink one of three LEDs. The timer is called
within a For Loop which repeatedly calls a function that alternately flashes the
other two LEDs. The timer is "turned on" runs for a specified portion of the For Loop
and is then "turned off".
*/
#include <TimerOne.h>
const int blinkLed = 3; // the pin with a LED that should blink
const int buttonLed1 = 4; // led controlled by button
@navillus5
navillus5 / gist:7460740
Created November 14, 2013 03:14
H-Bridge Control Example
/* Example code for a four transistor, four diode
H-Bridge
*/
// Assign four H-Bridge inputs to PWM pins
int r1 = 6;
int r2 = 9;
int r3 = 10;
int r4 = 11;
/*
Debounce
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).
The circuit:
* LED attached from pin 13 to ground
// Define constants
const int buttonPin = 2;
// Define variables
boolean buttonState = HIGH;
// Setup
// Define constants
const int buttonPin = 2;
// Define variables
boolean buttonState = HIGH;
// Setup
@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
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 / 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
@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 / 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"