Design a click counter with count-save capability using arduino uno c++ You are required to upgrade the click counter fr
Posted: Sun May 15, 2022 8:07 am
Design a click counter with
count-save capability using arduino uno c++
You are required to upgrade the click
counter from lab 3 with a feature that allows the counter to save
the current count value in the non-volatile EEPROM memory in the
MCU. The counter now has 5 push-buttons described as follows:
Count_up: increment
the current count.
Count_down: decrement
the current count.
Reset: resets the
current count.
Load: load the value
stored in EEPROM into the current count.
Save: Save the
current count in EEPROM.
The current count should always be
displayed on the LCD similar to Lab 3. You can assume that the
maximum count is 255, and the minimum count is 0.
#include <LiquidCrystal.h>
#include <EEPROM.h>
const int rs = A5, en = A4, d4 = A3, d5 = A2, d6 = A1, d7 =
A0;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int count_up= 0;
const int count_down=1 ;
const int reset=2;
const int load=3;
const int save=4;
int currentStateofUp=0;
int currentStateofDown=0;
int currentStateofRes=0;
int currentStateofload=0;
int currentStateofSave=0;
int laststate=0;
int count;
void setup() {
lcd.begin(16,2);
Serial.begin(9600);
pinMode(count_up,INPUT_PULLUP);
pinMode(count_down,INPUT_PULLUP);
pinMode(reset,INPUT_PULLUP);
pinMode(save,INPUT_PULLUP);
pinMode(load,INPUT_PULLUP);
lcd.setCursor(4,0);
lcd.print("Counter");
}
void loop() {
currentStateofUp= digitalRead(count_up);
currentStateofDown= digitalRead(count_down);
currentStateofRes= digitalRead(reset);
currentStateofload= digitalRead(load);
currentStateofSave= digitalRead(save);
if(currentStateofUp !=laststate){
if(currentStateofUp== LOW){
count++;
lcd.setCursor(0,1);
lcd.println(count);
}
delay(100);
}
laststate=currentStateofUp;
if(currentStateofDown !=laststate){
if(currentStateofDown== LOW){
count--;
lcd.setCursor(0,1);
lcd.println(count);
}
delay(100);
}
laststate=currentStateofDown;
if(currentStateofRes !=laststate){
if(currentStateofRes== LOW){
count=0;
lcd.setCursor(0,1);
lcd.println(count);
}
delay(100);
}
}
I did the above code for the count up, count down, reset, and
assigned each button to their ports accordingly. The only part of
the question that is left is the save button and the load
button.
Hd 44780-2 count_up Arduino Uno-1 countdown A5 ORX -1 TX 2 3 PWM reset 5 PWM 6 PWM 7 472272 saa load GND GND 5V 3V3 RST 8 9 PWM 10 PWM 11 PWM 12 13 O GND Aref save f
count-save capability using arduino uno c++
You are required to upgrade the click
counter from lab 3 with a feature that allows the counter to save
the current count value in the non-volatile EEPROM memory in the
MCU. The counter now has 5 push-buttons described as follows:
Count_up: increment
the current count.
Count_down: decrement
the current count.
Reset: resets the
current count.
Load: load the value
stored in EEPROM into the current count.
Save: Save the
current count in EEPROM.
The current count should always be
displayed on the LCD similar to Lab 3. You can assume that the
maximum count is 255, and the minimum count is 0.
#include <LiquidCrystal.h>
#include <EEPROM.h>
const int rs = A5, en = A4, d4 = A3, d5 = A2, d6 = A1, d7 =
A0;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int count_up= 0;
const int count_down=1 ;
const int reset=2;
const int load=3;
const int save=4;
int currentStateofUp=0;
int currentStateofDown=0;
int currentStateofRes=0;
int currentStateofload=0;
int currentStateofSave=0;
int laststate=0;
int count;
void setup() {
lcd.begin(16,2);
Serial.begin(9600);
pinMode(count_up,INPUT_PULLUP);
pinMode(count_down,INPUT_PULLUP);
pinMode(reset,INPUT_PULLUP);
pinMode(save,INPUT_PULLUP);
pinMode(load,INPUT_PULLUP);
lcd.setCursor(4,0);
lcd.print("Counter");
}
void loop() {
currentStateofUp= digitalRead(count_up);
currentStateofDown= digitalRead(count_down);
currentStateofRes= digitalRead(reset);
currentStateofload= digitalRead(load);
currentStateofSave= digitalRead(save);
if(currentStateofUp !=laststate){
if(currentStateofUp== LOW){
count++;
lcd.setCursor(0,1);
lcd.println(count);
}
delay(100);
}
laststate=currentStateofUp;
if(currentStateofDown !=laststate){
if(currentStateofDown== LOW){
count--;
lcd.setCursor(0,1);
lcd.println(count);
}
delay(100);
}
laststate=currentStateofDown;
if(currentStateofRes !=laststate){
if(currentStateofRes== LOW){
count=0;
lcd.setCursor(0,1);
lcd.println(count);
}
delay(100);
}
}
I did the above code for the count up, count down, reset, and
assigned each button to their ports accordingly. The only part of
the question that is left is the save button and the load
button.
Hd 44780-2 count_up Arduino Uno-1 countdown A5 ORX -1 TX 2 3 PWM reset 5 PWM 6 PWM 7 472272 saa load GND GND 5V 3V3 RST 8 9 PWM 10 PWM 11 PWM 12 13 O GND Aref save f