byte index = constrain(lightValue / 100, 0, 9);
Arduino程式碼
const byte seven[10] ={ B1111110, B0110000, B1101101, B1111001, B0110011, B1011011, B1011111, B1110000, B1111111, B1111011 }; const byte CdS = A4; void setup() { DDRD = B11111111; DDRB = B00000011; Serial.begin(9600); } void loop() { int lightValue = analogRead(CdS); byte index = constrain(lightValue / 100, 0, 9); PORTD = seven[index]; Serial.println(lightValue); delay(1000); }
程式碼ino檔
github下載