ใช้volumeปรับความสว่าง

หลักการทำงาน
เมื่อvolumeปรับค่าตัวresisterแล้วส่งไปยังarduino แล้วก็นำไปแสดงผลที่lde



Code
// ค่าคงที่เหล่านี้จะไม่เปลี่ยนแปลง พวกมันถูกใช้เพื่อตั้งชื่อให้กับพินที่ใช้:
const int analogInPin = A0;
const int analogOutPin = 9;

int sensorValue = 0;       
int outputValue = 0;     

void setup() {
  // เริ่มต้นการสื่อสารแบบอนุกรมที่ 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // อ่านค่าอนาล็อก:
  sensorValue = analogRead(analogInPin);
  // แม็พกับช่วงของแอนะล็อก:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // เปลี่ยนค่า analog out:
  analogWrite(analogOutPin, outputValue);

  // พิมพ์ผลลัพธ์ไปที่มอนิเตอร์อนุกรม:serial monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

// รอ 2 มิลลิวินาทีก่อนลูปถัดไปสำหรับตัวแปลงสัญญาณอนาล็อกเป็นดิจิตอลเพื่อชำระ หลังจากอ่านครั้งสุดท้าย:
  delay(2);
}

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

สัญลักษณ์ Flowchart

การต่อLDRแสดงผลที่LCD

วงจรนับ