Author: Not specified Language: cpp
Description: Not specified Timestamp: 2013-06-01 16:34:55 +0000
View raw paste Reply
  1. /*
  2.   DigitalReadSerial
  3.  Reads a digital input on pin 2, prints the result to the serial monitor
  4.  
  5.  This example code is in the public domain.
  6.  */
  7.  
  8. // digital pin 2 has a pushbutton attached to it. Give it a name:
  9. int pushButton = 2;
  10.  
  11. // the setup routine runs once when you press reset:
  12. void setup() {
  13.   // initialize serial communication at 9600 bits per second:
  14.   Serial.begin(9600);
  15.   // make the pushbutton's pin an input:
  16.   pinMode(pushButton, INPUT);
  17. }
  18.  
  19. template<typename T>
  20. struct base {
  21.   typedef int type;
  22. };
  23.  
  24. template<>
  25. struct base<double> {
  26.   typedef double type;
  27. };
  28.  
  29. // the loop routine runs over and over again forever:
  30. void loop() {
  31.   // read the input pin:
  32.   int buttonState = digitalRead(pushButton);
  33.   // print out the state of the button:
  34.   Serial.println(buttonState);
  35.   delay(1);        // delay in between reads for stability
  36. }
  37.  
  38.  
View raw paste Reply