Human-written demonstration (OpenAssistant volunteers)· OpenAssistant (human-written)
OpenAssistant Conversations (oasst2)
could you write the code for an arduino controller that will at the press of a button,…
In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
- User
could you write the code for an arduino controller that will at the press of a button, turn on an LED, wait 3 seconds and turn it off ?
- Assistant
Sure! Here is the code you can use to control an LED with a button on an Arduino board. This code will turn on an LED when you press a button, wait for 3 seconds, and then turn it off.
c++int ledPin = 13; // LED connected to digital pin 13 int buttonPin = 2; // button connected to digital pin 2 int buttonState = 0; // variable for reading the button status void setup() { pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output pinMode(buttonPin, INPUT); // sets the digital pin 2 as input } void loop() { buttonState = digitalRead(buttonPin); // read the state of the button if (buttonState == HIGH) { // if button is pressed digitalWrite(ledPin, HIGH); // turn on LED delay(3000); // wait for 3 seconds digitalWrite(ledPin, LOW); // turn off LED } }You can copy and paste this code into the Arduino IDE and upload it to your board. Let me know if you have any questions!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.