Arduino Uno Цифровые контакты ввода-вывода
delay(5); //wait 5ms current = digitalRead(BUTTON); //read it again
Download 1.39 Mb.
|
3-MAVZU
delay(5); //wait 5mscurrent = digitalRead(BUTTON); //read it again}return current; //return the current value}Часть 3void loop(){currentButton = debounce(lastButton); //read debounced stateif (lastButton == LOW && currentButton == HIGH) //if it was pressed…{ledOn = !ledOn; //toggle the LED value}lastButton = currentButton; //reset button valuedigitalWrite(LED, ledOn);}Управление RBG-светодиодомЧасть 1const int BLED=9; //Blue LED on Pin 9const int GLED=10; //Green LED on Pin 10const int RLED=11; //Red LED on Pin 11const int BUTTON=2; //The Button is connected to pin 2boolean lastButton = LOW; //Last Button Stateboolean currentButton = LOW; //Current Button Stateint ledMode = 0; //Cycle between LED statesЧасть 2void setup(){pinMode (BLED, OUTPUT); //Set Blue LED as OutputpinMode (GLED, OUTPUT); //Set Green LED as OutputpinMode (RLED, OUTPUT); //Set Red LED as OutputpinMode (BUTTON, INPUT); //Set button as input (not required)}Часть 3boolean debounce(boolean last){boolean current = digitalRead(BUTTON); //Read the button stateif (last != current) //if it's different...{delay(5); //wait 5mscurrent = digitalRead(BUTTON); //read it again}return current; //return the current value}Часть 4void setMode(int mode){//REDif (mode == 1){digitalWrite(RLED, HIGH);digitalWrite(GLED, LOW);digitalWrite(BLED, LOW);}//GREENelse if (mode == 2){digitalWrite(RLED, LOW);digitalWrite(GLED, HIGH);digitalWrite(BLED, LOW);}Download 1.39 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling