Perbedaan delay dan Millis. Penjelasan koding blink without delay untuk awam.

  Рет қаралды 1,692

Ronald Rezal

Ronald Rezal

Күн бұрын

Пікірлер: 17
@Bang.sand7
@Bang.sand7 9 ай бұрын
Terimakasih bang, penjelasannya sangat mudah dipahami buat orang awam seperti saya🙏🏻
@rinaandriani751
@rinaandriani751 3 жыл бұрын
Langsung masuk di otak,, Bahkan otak bebal sepertiku
@tohirincupaxkreatif4791
@tohirincupaxkreatif4791 2 жыл бұрын
set up brrti kaya command...cmd?
@gobex1459
@gobex1459 4 жыл бұрын
Tutor buat program neopixel bang🙏🙏🙏
@RonaldRezal
@RonaldRezal 3 жыл бұрын
udah banyak
@nurdiansyahusman
@nurdiansyahusman 4 жыл бұрын
Mas sy punya pus led button 1 button 4 fungi..pertam tekan sekali led 1 nyala, double klik led 2 nyala, tahan 1 detik led 3 nyala, tahan 2 detik led 4 nyala.. tp di led 3 dan 4 ada bermssalah.. kl misalkan sy mau menyalakan led 4 doang maka led 3 akan nyala dlu. Trs sy tahan lagi 1 detik utk mematikan led 3 agar hanya led 4 aja yg nyala.. nah maunya kl misal ditahan 2 detik utk menyalakan led 4 tp otmts lewat 1 detik led 3 gak nyala tp langsung led 4.. itu gmn ya mas? Makasih
@RonaldRezal
@RonaldRezal 4 жыл бұрын
Mana kodingnya mas ? Biar saya koreksi
@nurdiansyahusman
@nurdiansyahusman 4 жыл бұрын
#define buttonPin 19 // analog input pin to use as a digital input #define ledPin1 17 // digital output pin for LED 1 #define ledPin2 16 // digital output pin for LED 2 #define ledPin3 15 // digital output pin for LED 3 #define ledPin4 14 // digital output pin for LED 4 // LED variables boolean ledVal1 = false; // state of LED 1 boolean ledVal2 = false; // state of LED 2 boolean ledVal3 = false; // state of LED 3 boolean ledVal4 = false; // state of LED 4 //================================================= void setup() { // Set button input pin pinMode(buttonPin, INPUT); digitalWrite(buttonPin, HIGH ); // Set LED output pins pinMode(ledPin1, OUTPUT); digitalWrite(ledPin1, ledVal1); pinMode(ledPin2, OUTPUT); digitalWrite(ledPin2, ledVal2); pinMode(ledPin3, OUTPUT); digitalWrite(ledPin3, ledVal3); pinMode(ledPin4, OUTPUT); digitalWrite(ledPin4, ledVal4); } void loop() { // Get button event and act accordingly int b = checkButton(); if (b == 1) clickEvent(); if (b == 2) doubleClickEvent(); if (b == 3) holdEvent(); if (b == 4) longHoldEvent(); } //================================================= // Events to trigger by click and press+hold void clickEvent() { ledVal1 = !ledVal1; digitalWrite(ledPin1, ledVal1); } void doubleClickEvent() { ledVal2 = !ledVal2; digitalWrite(ledPin2, ledVal2); } void holdEvent() { ledVal3 = !ledVal3; digitalWrite(ledPin3, ledVal3); } void longHoldEvent() { ledVal4 = !ledVal4; digitalWrite(ledPin4, ledVal4); } // Button timing variables int debounce = 20; // ms debounce period to prevent flickering when pressing or releasing the button int DCgap = 250; // max ms between clicks for a double click event int holdTime = 2000; // ms hold period: how long to wait for press+hold event int longHoldTime = 5000; // ms long hold period: how long to wait for press+hold event // Other button variables boolean buttonVal = HIGH; // value read from button boolean buttonLast = HIGH; // buffered value of the button's previous state boolean DCwaiting = false; // whether we're waiting for a double click (down) boolean DConUp = false; // whether to register a double click on next release, or whether to wait and click boolean singleOK = true; // whether it's OK to do a single click long downTime = -1; // time the button was pressed down long upTime = -1; // time the button was released boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered boolean waitForUp = false; // when held, whether to wait for the up event boolean holdEventPast = false; // whether or not the hold event happened already boolean longHoldEventPast = false;// whether or not the long hold event happened already int checkButton() { int event = 0; // Read the state of the button buttonVal = digitalRead(buttonPin); // Button pressed down if (buttonVal == LOW && buttonLast == HIGH && (millis() - upTime) > debounce) { downTime = millis(); ignoreUp = false; waitForUp = false; singleOK = true; holdEventPast = false; longHoldEventPast = false; if ((millis()-upTime) < DCgap && DConUp == false && DCwaiting == true) DConUp = true; else DConUp = false; DCwaiting = false; } // Button released else if (buttonVal == HIGH && buttonLast == LOW && (millis() - downTime) > debounce) { if (not ignoreUp) { upTime = millis(); if (DConUp == false) DCwaiting = true; else { event = 2; DConUp = false; DCwaiting = false; singleOK = false; } } } // Test for normal click event: DCgap expired if ( buttonVal == HIGH && (millis()-upTime) >= DCgap && DCwaiting == true && DConUp == false && singleOK == true) { event = 1; DCwaiting = false; } // Test for hold if (buttonVal == LOW && (millis() - downTime) >= holdTime) { // Trigger "normal" hold if (not holdEventPast) { event = 3; waitForUp = true; ignoreUp = true; DConUp = false; DCwaiting = false; //downTime = millis(); holdEventPast = true; } // Trigger "long" hold if ((millis() - downTime) >= longHoldTime) { if (not longHoldEventPast) { event = 4; longHoldEventPast = true; } } } buttonLast = buttonVal; return event; }
@nurdiansyahusman
@nurdiansyahusman 4 жыл бұрын
Contoh Video di yutube sy mas..
@KnightBear123
@KnightBear123 Жыл бұрын
Oooooohhhh jadi delay cuman bisa 1 pekerjaan dan millis bisa 2 pekerjaan
@dinosabtu7475
@dinosabtu7475 4 жыл бұрын
Grup nya apa bang? Boleh gabung
@RonaldRezal
@RonaldRezal 4 жыл бұрын
Grup Facebook belajar arduino mas. Bukan grup wa.
@dinosabtu7475
@dinosabtu7475 4 жыл бұрын
Boleh gabung bang ke grup fb nya
@RonaldRezal
@RonaldRezal 4 жыл бұрын
@@dinosabtu7475 silahkan mas.
@dinosabtu7475
@dinosabtu7475 4 жыл бұрын
Namanya apa bang grupnya, biar aku cari
@just-havingfun428
@just-havingfun428 4 жыл бұрын
Contoh penerapannya dalam program yg lain coba bikin bang, hehe
@RonaldRezal
@RonaldRezal 4 жыл бұрын
Sip. Mungkin next mas.
Tutorial ARDUINO 2024 | Dari 0 Untuk Pemula
51:38
Dea Afrizal
Рет қаралды 493 М.
Cara merubah delay menjadi millis pada coding Arduino
15:26
Ronald Rezal
Рет қаралды 4,3 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
STM32 Guide #2: Registers + HAL (Blink example)
30:02
Mitch Davis
Рет қаралды 213 М.
Belajar Ngoding Dasar Untuk Pemula | #1 Dasar Untuk Pemula
27:34
BELAJAR CODING OTODIDAK
Рет қаралды 662 М.
Brain Rot Mengintai Gen Z | Halo Indonesia
19:30
DAAI Magazine
Рет қаралды 208 М.
Tutorial Pemrograman Arduino [Medium] -Apa itu millis di Arduino
17:45
Coders Indonesia
Рет қаралды 17 М.
ESP32 Sound - Working with I2S
46:04
DroneBot Workshop
Рет қаралды 353 М.
Buzzer Duration Using the while() and millis() Commands
14:30
belajar arduino - millis - jeda tanpa delay
13:11
Rifqi Baihaqi
Рет қаралды 2,4 М.
Arduino millis() function: 5+ things to consider
12:49
Programming Electronics Academy
Рет қаралды 144 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН