#include <LiquidCrystal.h>
const int rs = 12, e = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7;
LiquidCrystal LCD(rs, e, d4, d5, d6, d7);
float vol;
void setup() {
Serial.begin(9600);
LCD.begin(16, 2);
pinMode(6, OUTPUT);
}
void loop() {
for (vol = 0; vol <=255; vol++) {
delay(80);
LCD.setCursor(0, 1);
LCD.print("vol:");
LCD.print(vol);
LCD.print(" ");
if (vol <= 0) {
LCD.setCursor(0, 0);
LCD.print(" ");
}
if (vol >= 1) {
LCD.setCursor(0, 0);
LCD.print("MIN");
}
if (vol >= 128) {
LCD.setCursor(6, 0);
LCD.print("MED");
}
if (vol >= 255) {
LCD.setCursor(13, 0);
LCD.print("MAX");
}
if (vol < 255) {
LCD.setCursor(13, 0);
LCD.print(" ");
}
if (vol < 128) {
LCD.setCursor(6, 0);
LCD.print(" ");
}
analogWrite(6, vol);
}
for (vol = 255; vol >=0; vol--) {
delay(80);
LCD.setCursor(0, 1);
LCD.print("vol:");
LCD.print(vol);
LCD.print(" ");
if (vol < 255) {
LCD.setCursor(13, 0);
LCD.print(" ");
}
if (vol < 128) {
LCD.setCursor(6, 0);
LCD.print(" ");
}
analogWrite(6, vol);
}
}