Question

Conduct an experiment with Arduino using a Button sensor and a LED (connect sensors to Arduino...

Conduct an experiment with Arduino using a Button sensor and a LED (connect sensors to Arduino appropriately). Initially, the LED must blink with a delay of 1000 milliseconds (ms), which means it goes on for 1000 ms then off for 1000 ms. When the user presses the button, the delay is decreased by 100 ms. However, if the delay becomes equal to or less than 0 then you have to set the delay back to 1000 ms.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

int buttonpushPin=2;   //number where button is connected
int ledPin=13;    //number where the led is connected
int pushState=0;   //default button state


void setup()
{
   pinMode(ledPin, OUTPUT);       //Ledpin initialized to output mode
   pinMode(buttonpushPin, INPUT);   //Buttonpin initialized to input mode
}

void loop()
{
   int x=1000;
   while(x!=-1)
   {
       digitalWrite(13, HIGH);       //Led On
       delay(x);               //delay
       digitalWrite(13, LOW);       //Led off
       delay(x);               //delay
       pushState=digitalRead(buttonpushPin);   //Read button state
       if(pushState = HIGH)
           x=x-100;
       if(x<=0)
           x=1000;
   }
}
      


    

Add a comment
Know the answer?
Add Answer to:
Conduct an experiment with Arduino using a Button sensor and a LED (connect sensors to Arduino...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED str...

    I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...

  • Please help me! For Problem 1, 2 and 3: You are required to submit three .c...

    Please help me! For Problem 1, 2 and 3: You are required to submit three .c files that contain the instructions that you have written to solve the following problems. Place the C source code to solve the first problem in a file called lab5a.c. Place the C source code to solve the second problem in a file called lab5b.c. And place the C source code to solve the third problem in a file called lab5c.c. Remember to include your...

  • Experiment I: Malus' Law Questions The orientation of these polarizing filters can't be measured with great...

    Experiment I: Malus' Law Questions The orientation of these polarizing filters can't be measured with great accuracy because they re not marked off in small increments. Estimate the maximum uncertainty in measuring @ in this experiment. Justify your estimate. 1 with theory. Let's assume your 21 From your data table, choose the trial in poorest agre 1/1 measurement was accurate, but that the angle was not accurate. Calculate the angle that would theoretically yield this value of 1/1 measured angle....

  • Java Painter Class This is the class that will contain main. Main will create a new...

    Java Painter Class This is the class that will contain main. Main will create a new Painter object - and this is the only thing it will do. Most of the work is done in Painter’s constructor. The Painter class should extend JFrame in its constructor.  Recall that you will want to set its size and the default close operation. You will also want to create an overall holder JPanel to add the various components to. It is this JPanel that...

  • Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around...

    Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around risk and threat management, fostering an environment in which objectives seem clear: manage risk, manage threat, stop attacks, identify attackers. These objectives aren't wrong, but they are fundamentally misleading.In this session we'll examine the state of the information security industry in order to understand how the current climate fails to address the true needs of the business. We'll use those lessons as a foundation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT