FlevasGR

Simple Arduino Tilt

May 29th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. /*
  2. * THIS WILL BRING SKYNET BACK TO LIFE
  3. */
  4. #include <LiquidCrystal.h>
  5. #include <Scheduler.h>
  6.  
  7. const int tiltX = 10;
  8.  
  9. const int led = 13;
  10.  
  11. int XtiltState = 0;
  12.  
  13. void setup () {
  14.  
  15.   Serial.begin(9600);
  16.  
  17.   Scheduler.startLoop(tiltcheck);
  18.  
  19.   Serial.println("Program started");
  20.  
  21.   pinMode(tiltX, INPUT);
  22.  
  23.   pinMode(led, OUTPUT);
  24.  
  25. }
  26.  
  27. void loop () {
  28.    
  29. }
  30.  
  31. void tiltcheck () {
  32.   XtiltState = digitalRead(tiltX);
  33.  
  34.   if (XtiltState == HIGH) {
  35.    
  36.     Serial.println("Tilted on X axes");
  37.    
  38.     digitalWrite(led, HIGH);
  39.    
  40.   } else {
  41.    
  42.      digitalWrite(led, HIGH);
  43.      
  44.      delay(1000);
  45.      
  46.      digitalWrite(led, LOW);
  47.    
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment