ketna13
November 11, 2021, 11:21am
1
Hey, I am a beginner at programming and I'm stuck at this assignment where I have to change this code so when movement is detected the light bulb would turn on for a minute without delay() and then turn off again. I would appreciate any help I can get. And sorry if my English is rough it's not my native language.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
pinMode(A5, OUTPUT);
pinMode(A3, INPUT);
}
void loop() {
byte mA3 = digitalRead(A3);
String msg;
if(mA3){
msg = "Movement";
digitalWrite(A5, HIGH);
}
else{
msg = "No movement";
digitalWrite(A5, LOW);
}
lcd.home();
lcd.print(msg);
lcd.print(" ");
}
You want someone just to write the code for you or are you looking for a hand with writing the code so you can learn something?
ketna13
November 11, 2021, 11:28am
3
Looking for a hand so I can learn something
ketna13
November 11, 2021, 1:07pm
5
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 60000;
String msg = "No movement";
void setup() {
lcd.begin(16, 2);
pinMode(A5, OUTPUT);
pinMode(A3, INPUT);
}
void loop() {
byte mA3 = digitalRead(A3);
String msg;
if(mA3){
msg = "Movement";
digitalWrite(A5, HIGH);
startMillis = millis();
}
else{
currentMillis = millis();
if (currentMillis - startMillis >= period){
msg = "No movement";
digitalWrite(A5, LOW);
}
}
lcd.home();
lcd.print(msg);
lcd.print(" ");
}
Thanks for all the links, I updated my code using millis tutorial and it works perfectly now. Thanks for all the help.
1 Like
system
Closed
October 23, 2022, 9:03am
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.