write a code in C on RaspberryPi to have an LED light turn on and off using a push button
Answer :
please upvote if its upto your expectation or comment for any query . Thanks
I am writing code for Raspberry pi 3 .
Hardware connection :
1. LED 3.3v connected to GPIO 2 which is BCM2 (SDA ) with 100 ohm resistor .
2. PUSH button 1 connected to GPIO 3 which is SCL pin . (for turn on led)
3. PUSH button 2 connected to GPIO17 to turn off led
Program Plan :
1. set GPIO2 led pin as OUTPUT .
2. set GPIO3 push button pin as INPUT and set pullup resistor high to detect low on push button pin .
3. run a while loop where we will check continuously push button.
4. in if statement will check for push button pressed if pressed we will get 0 of pin status and will set LED high .
5. if second button pressed turn off led.
Code :
#include <wiringPi.h> //hardware definition file #include <stdio.h> #define LED 2 //GPIO 2 #define OnButton 3 //GPIO 3 to turn on led #define OffButton 17 //GPIO 17 to turn off led int main(void) { pinMode(LED, OUTPUT); //set o/p to led pin pinMode(OnButton, INPUT); //set input on button pin pinMode(OffButton, INPUT); //set input on button pin pullUpDnControl(OnButton, PUD_UP); //pull up set to detect low on pin pullUpDnControl(OffButton, PUD_UP); //pull up set to detect low on pin while(1){ if(digitalRead(OnButton) == 0){ //button presses digitalWrite(LED, HIGH); //Set LED high delay(100); //debounce time } else if(digitalRead(OffButton)==0){ digitalWrite(LED,LOW); //turn off led delay(100); //debounce time } } return 0; }
write a code in C on RaspberryPi to have an LED light turn on and off...
C CODE LANGUAGE. MSP430. #include <msp430fr6989.h> #define redLED BIT0 // Red LED at P1.0 #define greenLED BIT7 // Green LED at P9.7 #define BUT1 BIT1 // Button S1 at P1.1 #define BUT2 BIT2 // Button S2 at P1.2 void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop the Watchdog timer PM5CTL0 &= ~LOCKLPM5; // Enable the GPIO pins // Configure and initialize LEDs P1DIR |= redLED; // Direct pin as output P9DIR |= greenLED; // Direct pin as output...
Microcontroller programming exercises by practice on Arduino: Write a program that lights a green LED attached to pin 3. The green LED should turn off after a button attached to pin4 has been pushed and released 3 times. Each time the button is pushed it will turn on a red LED attached to pin 7 and turn off a yellow LED attached to pin 9. When the button is not pushed the red LED will be off and the yellow...
Write a program in CircuitPython to run on the FM4E that will turn on the heater for one minute if the button is pressed. The LED should be turned on when the heater is on, and it should go off when the heater turns off after one minute. Make sure your code has comments.
A button is connected to p1.0 and an LED is connected to P2.0. Write code with PWM so that if the button is pressed the LED is on 70%, but if the button is not pressed the LED is on 10%
Write an Arduino code to read the current temperature using the LM35 temperature sensor. The code should include the following if the temperature is more than 45 "C: • Turn ON red LED, and after 1 second turn ON the yellow LED, and after another 2 seconds tum On the Green LED. One second later the three LEDS should start blinking (all LEDs OFF for 0.5 seconds, then all LEDS ON for 1 minute), and turn OFF all LEDs after...
Design a circuit that safely turns an LED on when the lights in the room turn OFF. The LED should have a nearly constant output(current) while illuminated. Must use a single LED, a single 741 op amp and a light dependent resistor. Resistor value can be vary.
Questions 3 Write a Python program that implements the following functionality: 1. Makes an LED blink. 2. Then, on a push of a button the blinking stops. 3. Then, on another push of a button the blinking starts again 4. The behavior of steps 2 and 3 keeps repeating whenever the button is pushed. In writing your program, you should use a class, call it Blinkclass, that helps in making the LED blink or not. Connect the needed circuit using...
4. In this problem you will use CodeWarrior to develop the code to implement a three-light traffic signal. The program should do the following: a. Turn on a green LED attached to Port B bit 2 for 60 seconds, b. Turn off the green LED and turn on a yellow LED attached to Port B bit 1 for 30 seconds, c. Turn off the yellow LED and turn on a red LED attached to Port B bit 0 for 60...
ARM assembly lang please write code Street Crossing - This consists of a street light (red,yellow,green row of LEDs), and a separate red and green led (walk/dont walk) and a button. When the button is pressed, the red lights light up and the green indicator for walk lights up. Eventually the green and yellow will flash saying time to walk is over, then the red for dont walk lights up, and green for traffic lights up.
It's an Energia sketch using C language. We work with MSP430 Launchpad but you shouldn't need it to write the code. I'm really stuck :( Problem 2 (50 points) One common method of outputting an "effective" analog signal is to use pulse width modulation or PWM. In this modulation scheme, a high frequency square wave is switched on and off with a duty cycle determined by the desired output intensity, where Duty Cycle = Time spend "on" Total period 50%...