printf("ho_tari\n");

07_Analog_Read 본문

Arduino

07_Analog_Read

호타리 2023. 9. 2. 12:35
#define V0 5.0
#define unit V0/1024.0
#define R1 1000.0

const int analogPin = A0;
const int LED_0 = 3;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(LED_0, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  int analogValue = analogRead(analogPin);
  float V2 = analogValue * unit;
  float R2 = (V2 * R1) / (V0 - V2);
  Serial.print(analogValue);
  Serial.print(", ");
  Serial.print(V2);
  Serial.print("V, ");
  Serial.print(R2);
  Serial.println("Ω");

  int brightness = map(analogValue, 150, 1023, 0, 255);
  analogWrite(LED_0, brightness);

  delay(300);

}

'Arduino' 카테고리의 다른 글

09_Tone  (0) 2023.09.02
08_Joystick  (0) 2023.09.02
06_Switch_Input_Interrupt  (0) 2023.09.02
05_Switch_Input  (0) 2023.09.02
04_Serial_Read  (0) 2023.09.02