验证中...
使用数位计实现旋钮调灯亮度功能及使用1602屏实现实时显示灯的当前亮度功能。
Raw Copy
#include <LiquidCrystal_SoftI2C.h>
#include <SoftI2CMaster.h>
LiquidCrystal_SoftI2C mylcd(0x27,16,2,A1,A2);
volatile boolean state;
void setup(){
pinMode(3, OUTPUT);
state = 0;
mylcd.init();
mylcd.backlight();
digitalWrite(3,LOW);
pinMode(10, INPUT_PULLUP);
Serial.begin(9600);
}
void loop(){
Serial.println(digitalRead(10));
while (digitalRead(10) == 1) {
}
if (state == 0) {
analogWrite(3,125);
while (analogRead(A0)) {
analogWrite(3,(map(analogRead(A0), 0, 1023, 0, 255)));
Serial.println(analogRead(A0));
mylcd.setCursor(0, 0);
mylcd.print("2017764339");
mylcd.setCursor(0, 1);
mylcd.print(analogRead(A0));
}
} else {
digitalWrite(3,LOW);
state = !state;
}
delay(1000);
}

Comment list( 0 )

Sign in for post a comment

Help Search