Skip to content

Instantly share code, notes, and snippets.

/*
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
@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;
@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 / Timer1 Example A
Last active April 4, 2017 14:01
Timer! example 0
/* This example employs Timer1 to blink one of three LEDs. The timer is initialized and called
during the setup() function which repeatedly calls a function that alternately flashes the
other two LEDs. The timer function continues without interruption when the loop operates.
*/
#include <TimerOne.h>
// This example uses the timer interrupt to blink an LED
// This allows the main program to do "other stuff"
@navillus5
navillus5 / IR Remote 1
Last active April 4, 2017 13:55
Arduino IR Remote sample code
/*
* Having used the sketch IRrecvDemo from the IRremote library to
* determine the codes for four buttons on a remote, this code will
* now "listen" for these codes and control LEDs based upon what code
* has been received.
*/
#include <IRremote.h>
int ledPins[]={2,3,4,5,6,7};
void setup() {
for(int i=0; i < 6; i=i+1){
pinMode(ledPins[i],OUTPUT);
}
}
int ledPins[]={2,3,4,5,6,7};
int vol = 0;
void setup() {
for(int i=0; i < 6; i=i+1){
pinMode(ledPins[i],OUTPUT);
digitalWrite(ledPins[i],LOW);
}
Serial.begin(9600);
// The UML shield has 6 LEDs which can be used to display 6 bits of data
// The highest binary number that can be represented is 111111 which is the
// integer value 63.
int binValue[] = {0,0,0,0,0,0};
int ledArray[] = {2,3,4,5,6,7};
int val = 0;
void setup() {
Serial.begin(9600);
@navillus5
navillus5 / testLEDs
Created October 30, 2016 01:56
UMLshield test code - LED array
/*
* UML shield
* Test code for array of LED's connected to digital I/O pins
* 2, 3, 4, 5, and 6
*
* Board configuration: Jumper JP3 closed
*/
// Create a six element integer array for the pin numbers
@navillus5
navillus5 / MECH 2010 Stepper 2
Created March 23, 2017 14:45
Test code for operating a bipolar stepper motor in the higher torque mode using two active coils
int d = 5;
int count = 0;
void setup() {
Serial.begin(9600);
Serial.println(count);
// coil 1
pinMode(11,OUTPUT); // enable pin for coil 1