Rabu, 16 April 2014

ARDUINO - ADC & PWM Control Example

int potpin = A0; // input adc di pin A0
int adc,pwm; //inisialisasi nilai adc dan pwm

void setup()
{
  Serial.begin(9600); //baudrate serial
}

void loop()
{
  adc = analogRead(potpin); //baca nilai adc
  pwm = map(adc, 0, 1023, 0, 225); //mapping dari 10 bit ke 8 bit pwm atmega 328
  analogWrite(3, pwm); //keluaran pwm di pin D3
  Serial.print("Nilai ADC = "); //menampilkan adc di serial
  Serial.print(adc);
  Serial.print("\tNilai PWM= "); //menampilkan pwm di serial
  Serial.println(pwm);
  delay(15);
}

Tidak ada komentar:

Posting Komentar