تذكّر العداد بعد إعادة الضبط
احفظ الحالة عبر دورات تشغيل الطاقة.
تذكّر العداد بعد إعادة الضبط درس مجاني في Arduino & IoT Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Arduino & IoT Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
A Counter That Survives
Let's build a press counter that remembers its total even after a power cut. We'll combine debouncing with EEPROM storage.
The Plan in One Line
On startup, load the saved count. On each clean press, add one and save it back. Simple, but powerful.
Pick a Storage Slot
Reserve one EEPROM address for the counter. We'll keep it small enough to fit in a single byte for now.
const int ADDR = 0;
byte count = 0;Load on Boot
Inside setup(), read the saved value first. Now your counter picks up exactly where it left off.
void setup() {
count = EEPROM.read(ADDR);
}Wipe the Junk First
A fresh chip's EEPROM often reads 255. Treat that as empty and reset your counter to zero on the first run.
if (count == 255) count = 0;Reuse Your Debounce
Detect presses with the millis() debounce from before. Clean input is essential, or your saved count drifts upward.
Increment on a Clean Press
When a debounced press fires, bump the counter by one. This is the single moment your total grows.
count++;
Serial.println(count);Save Without Wearing Out
Use EEPROM.update to write the new total. It only touches memory when the value actually changed, protecting the chip.
EEPROM.update(ADDR, count);Test the Magic
Press a few times, then unplug and replug the board. The Serial Monitor shows your count continuing, not restarting. 🎉
Mind the Byte Limit
A byte counter wraps back to 0 after 255. For bigger totals, store an int with EEPROM.put and EEPROM.get instead.
Add a Reset Option
A real product often needs a way to clear the saved count. A long button hold could write 0 back to EEPROM.
EEPROM.update(ADDR, 0);Quick Check
Let's check the key step that lets the counter survive a reset.
Recap: Memory Across Resets
You built a counter that persists by loading from EEPROM at boot and saving each clean press. Your device finally has a memory! 🧠
الأسئلة الشائعة
هل درس «تذكّر العداد بعد إعادة الضبط» مجاني؟
نعم — نص درس «تذكّر العداد بعد إعادة الضبط» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Arduino & IoT Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.
ماذا ستتعلم في «تذكّر العداد بعد إعادة الضبط»؟
احفظ الحالة عبر دورات تشغيل الطاقة. تتمرن على Arduino & IoT Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Arduino & IoT Academy؟
لا تُشترط خبرة سابقة. Arduino & IoT Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «تذكّر العداد بعد إعادة الضبط»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Arduino & IoT Academy هذا؟
نعم. كل درس في Arduino & IoT Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- لماذا ترتد الأزرار
- إزالة ارتداد الإشارة باستخدام millis()
- تخزين قيمة في EEPROM
- تذكّر العداد بعد إعادة الضبط