把十进制转为二进制,可以脑补几个为2^n的盒子,把十进制数对号入座放进去就可以了。
重点:光敏电阻光照越强,阻值越低
光度越大,阻值越小;光度越小,阻值越大
然后有一个实验:
数值随着光敏电阻接受到的亮度变化而变化,亮度越低数值越低,反之亦然。
接下来制作电子贺卡
代码:
void sing() {
tone(10,392,250);
delay(250);
tone(10,392,250);
delay(250);
tone(10,440,500);
delay(500);
tone(10,392,500);
delay(500);
tone(10,532,500);
delay(500);
tone(10,494,1000);
delay(1000);
tone(10,392,250);
delay(250);
tone(10,392,250);
delay(250);
tone(10,440,500);
delay(500);
tone(10,392,500);
delay(500);
tone(10,589,500);
delay(500);
tone(10,525,1000);
delay(1000);
tone(10,392,250);
delay(250);
tone(10,392,250);
delay(250);
tone(10,786,500);
delay(500);
tone(10,661,500);
delay(500);
tone(10,525,500);
delay(500);
tone(10,496,500);
delay(500);
tone(10,441,500);
delay(500);
tone(10,700,250);
delay(250);
tone(10,700,250);
delay(250);
tone(10,661,500);
delay(500);
tone(10,525,500);
delay(500);
tone(10,589,500);
delay(500);
tone(10,525,2000);
delay(2000);
}
void setup(){
pinMode(2, OUTPUT);
pinMode(0, OUTPUT);
}
void loop(){
if (analogRead(A0) <= 100) {
digitalWrite(2,HIGH);
sing();
}
}