Question

In: Electrical Engineering

4. Write a code that S1(push button -P1.1) turns LED1 (Red LED- P1.0) ON and stays...

4. Write a code that S1(push button -P1.1) turns LED1 (Red LED- P1.0) ON and stays on when you push once and turns off and stays OFF when you push 3 times. This should repeat forever.

5. Write a code that S2(push button -P1.2) turns LED2 (Red LED- P9.7) ON and stays ON when you push once and turns OFF and stays OFF when you push 3 times. This should repeat five times.

6. Write a code that LED2 (Red LED- P9.7) ON when as long as you push S2(push button - P1.2) and LED1 (Red LED- P1.0) on as long as S2(push button -P1.2) not pushed.

Solutions

Expert Solution

#include <stdio.h>
enum LED1{
   ON,
   OFF
}led;   //enum variable for LED ON/OFF
int pushcount;   //counter to count push number
int flag;       //a flag to check LED switch off (Q no 2)
int button;       //global variable for push button
               //use your own variable to get pushbutton value

//Function to turn LED ON/OFF
void ledOnOff(int pushbutton)
{
   if(led==OFF)
   {
       if(pushbutton==1 && flag!=1)   //flag is used to check if LED turned Off
       {
           led=ON;
           pushcount=0;
       }
   }
   else
   {
       if(pushbutton==1)
       {
           pushcount++;
           if(pushcount==3)
           {
               led=OFF;
               pushcount=0;
           }
       }
   }
}

//Function to switch LED OFF
void ledSwitch(int pushbutton)
{
   if(led==OFF)
   {
       if(pushbutton==1)
       {
           pushcount++;
           if(pushcount==5 && flag!=1)
           {
               led=ON;
               pushcount=0;
           }
       }
   }
   else
   {
       int i;
       for(i=0;i<1000;i++);
       led=OFF;
       flag=1;
   }
}
int main()
{
   led=OFF;   //initialize LED to OFF
   pushcount=0;   //initialize pushcount to 0
   flag=0;       //initialise flag to 0
   while(1)   //continuous loop
   {
       ledOnOff(button);
       ledSwitch(button);
   }
   return 0;
}


Related Solutions

1.. Write a code that LED1 (Red LED- P1.0) turns ON when after you push S1(push...
1.. Write a code that LED1 (Red LED- P1.0) turns ON when after you push S1(push button - P1.1) five times and stays OFF forever after that. 2.. Write a code that LED1 (Red LED- P1.0) turns OFF and LED2 (Red LED- P9.7) Turns ON after you push S1(push button -P1.1) five times and they stay that way forever.
1. Write a code that makes the MSP430 blink the red LED and the green LED...
1. Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It...
1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It should turn off whenever S1 is released. 2. Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop.
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND STAYS ON THE ENTIRE TIME THE BOARD IS RUNNING EXCEPT AT 30 SECOND INTERVALS THEN LED 1 TURNS OFF AND BACK ON 2. LED 2 TURNS ON IN LIGHT CONDITIONS AND OFF IN DARK CONDITION THANK YOU!
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN DARK CONDITIONS AND OFF IN LIGHT CONDITIONS 2. LED 4 TURNS ON WITH FIRST BUTTON PRESS AND STAYS ON UNTIL A SECOND BUTTON PRESS
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
Write a program for the msp430 to make led1 and led 2 alternate blinking 2. repeat...
Write a program for the msp430 to make led1 and led 2 alternate blinking 2. repeat the program to make each led blink 5 times in a sequence, then 5 times simultaneously
An LED is connected to PD3 and a Button is connected to PD0. Write a C...
An LED is connected to PD3 and a Button is connected to PD0. Write a C program that will wait for the button to be pressed and then released (make sure you debounce the press and release). Each time the button is pressed, the LED blinks a number of times corresponding to how many times the button has been pressed and released. For example, when the button is pressed and released for the first time, the LED will blink once;...
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
using code composer studio 1. write a program for the msp430fr6989 that will light LED1, whenever...
using code composer studio 1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It should turn off whenever S1 is released. 2. Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT