D:/DRISSI/arduino-0022/arduino-0022/libraries/ledButton/ledButton.cpp
00001 /* Read buttons state and control leds consequently*/
00002 
00003 #include <ledButton.h>
00004 
00005 
00006 int ButtonOne = 1;     
00007 int ButtonTwo = 2; 
00008 int GreenPin =  13;      
00009 int RedPin =  12;
00010 
00011 
00012 // Initialize pinmode of the pins used for leds and buttons
00013 void InitLedButton()
00014 {
00015 #ifdef __DEBUG__
00016         Serial.println("Initialisation of leds and buttons...");
00017 #endif
00018         
00019         pinMode( GreenPin, OUTPUT);    
00020         pinMode( RedPin, OUTPUT);  
00021         pinMode(ButtonOne, INPUT);   
00022         pinMode(ButtonTwo, INPUT);  
00023 }
00024 
00025 
00026 // Use leds and buttons
00027 void LedButtonsState()
00028 {
00029 #ifdef __DEBUG__
00030         Serial.println("Control leds and read buttons state...");
00031 #endif
00032 
00033         int ButtonOneState = digitalRead(ButtonOne);
00034         int ButtonTwoState = digitalRead(ButtonTwo);      // Check if the pushbutton is pressed
00035                                                                                                   
00036         if (ButtonOneState == HIGH)                                               // If it is, the buttonState is HIGH
00037         {                                         
00038                 digitalWrite(GreenPin, HIGH);                             // Turn LED on 
00039         } 
00040         else                                                                                      // Else
00041         {
00042                 digitalWrite(GreenPin, LOW);                              // Turn LED off
00043         }
00044   
00045   
00046         if (ButtonTwoState == HIGH)                                               // If it is, the buttonState is HIGH
00047         {     
00048                 digitalWrite(RedPin, HIGH);                                       // Turn LED on     
00049         } 
00050         else                                                                                      // Else
00051         {
00052                 digitalWrite(RedPin, LOW);                                        // Turn LED off
00053         }
00054 }
00055