Tick Tock Counter EEPROM
ขั้นตอนที่ 1 นำ Code ข้างล่างนี้โหลดลงบอร์ด
#include <EEPROM.h>
#include "TM1636.h"
TM1636 tm1636(7, 8);
int8_t disp[4];
int count = 2008;
int counter = count;
int buttonMenu = 11;
int buttonUp = 10;
int buttonDown = 9;
int voice = 6;
int temp = count ;
int sensorPin = A0;
int sensorValue = 0;
void setup()
{
Serial.begin(9600);
Serial.println(EEPROM.read(0), HEX);
tm1636.init();
pinMode(buttonMenu, INPUT_PULLUP);
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
pinMode(voice, OUTPUT);
while (!Serial) {
}
}
void loop()
{
disp[0] = EEPROM.read(0);
disp[1] = EEPROM.read(1);
disp[2] = EEPROM.read(2);
disp[3] = EEPROM.read(3);
tm1636.display(disp);
if (digitalRead(buttonMenu) == 0) {
count = 2008;
temp = count;
disp[0] = temp / 1000; temp = count % 1000;
disp[1] = temp / 100; temp = count % 100;
disp[2] = temp / 10; temp = count % 10;
disp[3] = temp;
delay(160);
EEPROM.write(0, disp[0]);
EEPROM.write(1, disp[1]);
EEPROM.write(2, disp[2]);
EEPROM.write(3, disp[3]);
digitalWrite(voice, HIGH);
while (buttonMenu == 0) {}
delay(5);
digitalWrite(voice, LOW);
Serial.print("MonitorValue = ");
Serial.println(count);
tm1636.display(disp);
delay(100);
}
if (digitalRead(buttonUp) == 0) {
count = 0;
count = count + (disp[0] * 1000);
count = count + (disp[1] * 100);
count = count + (disp[2] * 10);
count = count + (disp[3] * 1);
count++;
temp = count;
disp[0] = temp / 1000; temp = count % 1000;
disp[1] = temp / 100; temp = count % 100;
disp[2] = temp / 10; temp = count % 10;
disp[3] = temp;
delay(160);
EEPROM.write(0, disp[0]);
EEPROM.write(1, disp[1]);
EEPROM.write(2, disp[2]);
EEPROM.write(3, disp[3]);
digitalWrite(voice, HIGH);
delay(5);
while (buttonUp == 0) {}
digitalWrite(voice, LOW);
Serial.print("MonitorValue = ");
Serial.println(count);
tm1636.display(disp);
delay(100);
}
if (digitalRead(buttonDown) == 0) {
count = 0;
count = count + (disp[0] * 1000);
count = count + (disp[1] * 100);
count = count + (disp[2] * 10);
count = count + (disp[3] * 1);
count--;
temp = count;
disp[0] = temp / 1000; temp = count % 1000;
disp[1] = temp / 100; temp = count % 100;
disp[2] = temp / 10; temp = count % 10;
disp[3] = temp;
delay(160);
EEPROM.write(0, disp[0]);
EEPROM.write(1, disp[1]);
EEPROM.write(2, disp[2]);
EEPROM.write(3, disp[3]);
digitalWrite(voice, HIGH);
delay(5);
while (buttonDown == 0) {}
digitalWrite(voice, LOW);
Serial.print("MonitorValue = ");
Serial.println(count);
tm1636.display(disp);
delay(100);
}
}
2.นำบอร์ด TickTock Shield มาประกอบร่างเข้ากับบอร์ด
Arduino ดังรูปเลยค้าบบบ
3.ลองถอดสายบอร์ดออกเพื่อทดสอบว่ามีการ save
ข้อมูลเข้าไปจริงไหม
4.ลองโหลดโค้ดลงบอร์ดีอกหนึ่งครั้ง
เพื่อดูว่าเลขที่เรากดไปครั้งล่าสุด กำลังแสดงอยู่หรือไม่
5.ลองทดสอบกับ labView ว่าค่าที่ได้แสดงใน
read String ไหม
0 ความคิดเห็น:
แสดงความคิดเห็น