验证中...
Languages: C/C++
Categories: 其他
Latest update 2019-11-09 17:16
完成使用继电器控制直流电机功能
Raw Copy
void setup(){
Serial.begin(9600);
pinMode(8, OUTPUT);
}
void loop(){
switch (Serial.read()) {
case 'a':
digitalWrite(8,HIGH);
break;
case 'b':
digitalWrite(8,LOW);
break;
}
}
通过按键控制继电器,实现按键控制直流电机功能
Raw Copy
volatile int b1;
volatile int b2;
volatile int click;
volatile int laststate;
volatile int toggle;
void setup(){
click = 0;
laststate = digitalRead(13);
toggle = 0;
b1 = 0;
b2 = 0;
pinMode(13, INPUT_PULLUP);
pinMode(8, OUTPUT);
}
void loop(){
if (digitalRead(13) == 0) {
b1 = !digitalRead(13);
if (b1 != laststate) {
delay(20);
b2 = digitalRead(13);
if (b1 == b2) {
laststate = b1;
click = click + 1;
}
}
if (click == 1) {
toggle = 1 - toggle;
digitalWrite(8,toggle);
}
if (click == 2) {
click = 0;
toggle = 1 - toggle;
digitalWrite(8,toggle);
}
delay(1000);
}
}

Comment list( 0 )

Sign in for post a comment

Help Search

191139_cd20d5fd_5186603 191143_ebef6f8d_5186603