In this lesson we learn how to incorporate a push button switch into our Jetson Nano projects. We explain the concept of a pull up resistor, and show how to configure the GPIO pins as inputs. This will allow you to take your NVIDIA Jetson Nano projects to new heights. Enjoy!
Tag Archives: Pushbutton
Arduino Tutorial 34: Simplest Way to Use a Pushbutton Switch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
int buttonPin=2; int buttonValue; int dt=100; void setup() { // put your setup code here, to run once: pinMode(buttonPin,INPUT); digitalWrite(buttonPin,HIGH); Serial.begin(9600); } void loop() { buttonValue=digitalRead(buttonPin); Serial.print("Your Button is: "); Serial.println(buttonValue); delay(dt); } |
Arduino Tutorial 28: Using a Pushbutton as a Toggle Switch
If you want to follow along at home, you can order the Arduino Kit we are using HERE.
Below is the code we used to achieve the toggle operation. The video gives details on how to connect up the circuit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
int LEDState=0; int LEDPin=8; int buttonPin=12; int buttonNew; int buttonOld=1; int dt=100; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(LEDPin, OUTPUT); pinMode(buttonPin, INPUT); } void loop() { buttonNew=digitalRead(buttonPin); if(buttonOld==0 && buttonNew==1){ if (LEDState==0){ digitalWrite(LEDPin,HIGH); LEDState=1; } else{ digitalWrite(LEDPin, LOW); LEDState=0; } } buttonOld=buttonNew; delay(dt); } |