Skip to content

Instantly share code, notes, and snippets.

@boxalljohn
Created July 15, 2013 05:07
Show Gist options
  • Select an option

  • Save boxalljohn/5997628 to your computer and use it in GitHub Desktop.

Select an option

Save boxalljohn/5997628 to your computer and use it in GitHub Desktop.
// Example 3.2 – interrupts
#include <LiquidCrystal.h> // we need this library for the LCD commands
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
float noisy = 0;
void setup()
{
lcd.begin(16, 2); // need to specify how many columns and rows are in the LCD unit
lcd.setCursor(0,0);
lcd.println('* example 3.2 * ');
lcd.setCursor(0,1);
lcd.println('tronixstuff.com ');
lcd.setCursor(0,1);
delay(4000);
lcd.clear();
randomSeed(analogRead(0)); // reseed the random number generator with some noise
attachInterrupt(0, panicone, RISING); // so when interrupt zero (digital pin 2) changes state, it will trigger the interrupt and go to function 'panicone'
attachInterrupt(1, panictwo, RISING); // so when interrupt one (digital pin 3) changes state, it will trigger the interrupt and go to function 'panictwo'
}
void loop()
{
noisy=random(1000);
lcd.setCursor(0,0);
lcd.print('Random Numbers!');
lcd.setCursor(0,1);
lcd.print('Number: ');
lcd.print(noisy,0);
delay(1000);
}
void panicone()
{
lcd.clear();
lcd.println('Interrupt one ');
}
void panictwo()
{
lcd.clear();
lcd.println('Interrupt two ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment