Exercise 1a
int x=0;
void
setup()
{
Serial.begin(9600);
Serial.println("Initializing...");
delay(100);
}
void
loop()
{
Serial.print("This is pwm_value: ");
Serial.println(x);
x=x+1;
delay(1000);
}
Exercise 2a
void
setup()
{
Serial.begin(9600);
}
void
loop()
{
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.print("sensorValue=");
Serial.print(sensorValue);
Serial.print(" voltage=");
Serial.println(voltage);
delay(100);
}
Exercise 3a
int pwmPin = 9;
int potPin = A0;
void setup()
{
pinMode(pwmPin, OUTPUT);
pinMode(potPin, INPUT);
Serial.begin(9600);
}
void loop()
{
int value = analogRead(potPin);
int duty = value/4;
analogWrite(pwmPin, duty);
Serial.print(value);
Serial.print("\t");
Serial.println(duty);
delay(100);
}
No comments:
Post a Comment