Analog Output

A Simple Analog Output

void setup()
{
Serial.begin(9600);
Serial.println(“Analog Output Example”);
pinMode(9, OUTPUT); // Red LED
}
byte output = 0;

void loop()
{
output++;
Serial.println(output);
analogWrite(9, output); // 0-255
}

 

A Pulsing LED

void setup()
{
Serial.begin(9600);
Serial.println(“Analog Output Example”);
pinMode(9, OUTPUT); // Red LED
}
byte output = 0;
bool dir = true;
void loop()
{
if (dir)
output++;
else
output–;
if (output == 255)
dir = false;
else if (output == 0)
dir = true;
Serial.println(output);
analogWrite(9, output); // 0-255
}