2. 程式:
void setup(){ // open a serial connection Serial.begin(9600); // make our digital pin an output pinMode(4, OUTPUT); //SDA(PWM0) pinMode(5, OUTPUT); //SCL(PWM1) } void loop(){ // read the input on A0 and map it to a PWM pin // with an attached LED int sensorVal = analogRead(A0); Serial.print("Analog Read) : "); Serial.print(sensorVal); // the default PWM resolution analogWriteResolution(8); analogWrite(4, map(sensorVal, 0, 1023, 0 ,255)); Serial.print(" , 8-bit PWM value : "); Serial.print(map(sensorVal, 0, 1023, 0 ,255)); // change the PWM resolution to 4 bits analogWriteResolution(4); analogWrite(5, map(sensorVal, 0, 1023, 0, 127)); Serial.print(", 4-bit PWM value : "); Serial.println(map(sensorVal, 0, 1023, 0, 127)); delay(100); }3. 結果:
沒有留言:
張貼留言