/*
online model of Arduino with AVT 1615
manual of shiels
https://serwis.avt.pl/manuals/AVT1615.pdf
project available in WOKWI ONLINE PLATFORM
https://wokwi.com/projects/359988057917665281
*/
#include <LiquidCrystal.h>
#include <stdio.h>
#include <math.h>
#include <avr/io.h>
// numeration of digital and analog pins in the AVT1615 BOARD
int ledPin10 = 10, ledPin11 = 11, ledPin12 = 12, ledPin13 = 13; // LED connected to digital pins 10-13
int buttonPin0 = 0, buttonPin1 = 1,buttonPin2 = 2, buttonPin3 = 3; // Buttons connected to digital pins 1-3
int sensorValue = 0, tempValue = 0; // variable to store the value coming from the potentiometer and sensor
int potentiometerPin = A0, thermometerPin = A1;
// initialize the library by associating any LCD interface pin with the arduino pin number it is connected to
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
char str[8];
char str2[8];
// ------------- INITIALIZATION -------------
void setup() {
// sets the digital pins 10-13 as output and set off (value 1)
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);
pinMode(ledPin13, OUTPUT);
digitalWrite(ledPin10, 1);
digitalWrite(ledPin11, 1);
digitalWrite(ledPin12, 1);
digitalWrite(ledPin13, 1);
// sets the digital pins 0-3 as input
pinMode(buttonPin0, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(potentiometerPin, INPUT);
// initialize screen and print a "hello, world!" message to the LCD.
lcd.begin(16, 2);
lcd.print("hello, world!");
delay(1000);
// initialize Serial (UART) communication
Serial.begin(9600);
}
// ------------- OPERATION N THE LOOP -------------
void loop() {
// TASK 0
// set all LEDs in the board one by one
// https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/
if (!digitalRead(buttonPin0)){
// set all LEDs in the board one by one
digitalWrite(ledPin10, 0);
digitalWrite(ledPin11, 1);
digitalWrite(ledPin12, 1);
digitalWrite(ledPin13, 1);
delay(250);
digitalWrite(ledPin10, 1);
digitalWrite(ledPin11, 0);
digitalWrite(ledPin12, 1);
digitalWrite(ledPin13, 1);
delay(250);
digitalWrite(ledPin10, 1);
digitalWrite(ledPin11, 1);
digitalWrite(ledPin12, 0);
digitalWrite(ledPin13, 1);
delay(250);
digitalWrite(ledPin10, 1);
digitalWrite(ledPin11, 1);
digitalWrite(ledPin12, 1);
digitalWrite(ledPin13, 0);
delay(250);
}
// TASK 1
// fade out from max to min in increments of 5 points
// fade in from min to max in increments of 5 points
// https://docs.arduino.cc/built-in-examples/analog/Fading
else if(!digitalRead(buttonPin1)){
// fade out from max to min in increments of 5 points
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// decrerase the value (range from 255 to 0):
analogWrite(ledPin10, fadeValue);
analogWrite(ledPin11, fadeValue);
analogWrite(ledPin12, fadeValue);
analogWrite(ledPin13, fadeValue);
delay(30);
}
// fade in from min to max in increments of 5 points
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// increase the value (range from 0 to 255):
analogWrite(ledPin10, fadeValue);
analogWrite(ledPin11, fadeValue);
analogWrite(ledPin12, fadeValue);
analogWrite(ledPin13, fadeValue);
delay(30);
}
}
// TASK 2
// display the name and city on the screen
// https://docs.arduino.cc/learn/electronics/lcd-displays
// display the name and city with serial communication
// https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-serial-monitor
else if (!digitalRead(buttonPin2)){
// display the name and city on the screen
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PAWEL KROL");
lcd.setCursor(0, 1);
lcd.print("KRAKOW");
// display the name and city with serial communication
Serial.println("PAWEL KROL");
Serial.println("KRAKOW");
delay(100);
}
// TASK 3
// read the value from the potentiometer and output to the LED proportional to the value read
// https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite
// display the measurement on the screen
// https://docs.arduino.cc/learn/electronics/lcd-displays
// send the measurement with serial communication
// https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-serial-monitor
else if (!digitalRead(buttonPin3)){
// read the value from the potentiometer and output to the LED proportional to the value read
sensorValue = analogRead(potentiometerPin);
analogWrite(ledPin10, (int)(sensorValue/1024.0*256.0));
//analogWrite(ledPin10, (int)(pow(sensorValue/1024.0, 1/2.2)*256.0)); // gamma correction https://www.scantips.com/lights/gamma2.html
// display the measurement on the screen
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(sensorValue);
// send the measurement with serial communication
Serial.println(sensorValue);
delay(100);
}
// IDDLE TASK
// read the value from the LM35 temperature sensor
// display the measurement on the screen
// send the measurement with serial communication
else{
tempValue = analogRead(thermometerPin);
// display the measurement on the screen
lcd.clear();
lcd.setCursor(0, 0);
sprintf(str, "ADC: %d", tempValue);
lcd.print(str);
lcd.setCursor(0, 1);
dtostrf((float)tempValue/1024.0*5.0*100.0, 2, 2, str); // https://www.programmingelectronics.com/dtostrf/
sprintf(str2, "TMP: %s", str); // https://docs.arduino.cc/built-in-examples/strings/StringAdditionOperator
lcd.print(str2);
// send the measurement with serial communication
Serial.println(str2);
delay(100);
}
}