Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*************************************************************************
- // Name : StereoAudioAmpDisplayLCD *
- // Author : Tarilayefa Edward *
- // Notice : Tari Electronics & Embedded Systems (TEES), 2018. *
- // : tarielectronics@yahoo.com *
- // : tarielect.edward@gmail.com *
- // : +23408184754883,+23408062251186, Nigeria. *
- // : https//:web.facebook.com/groups/teestraining/ *
- // : https//:web.facebook.com/groups/picarduino/ *
- // Date : 26/05/2018 *
- // Version : 1.0 *
- // Notes : A program to display stereo audio output display on a 16x2 *
- // : char lcd. *
- // Reference: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *
- // Compiler : avrgcc *
- // IDE : Arduino 1.8.5 *
- // Target : Atmega 328, Arduino Uno, Nano. *
- //*************************************************************************
- #include <LiquidCrystal.h> //add the lcd library
- LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //(rs,en,d4,d5,d6,d7)
- //#include <LiquidCrystal_SR.h> //add the 2/3 wire lcd library
- //LiquidCrystal_SR lcd(9,10);//(data,clock-2wire)or(data,clock,latch-3wire)
- //------------------------------------------------------------------------
- unsigned int lcdBarR;
- unsigned int lcdBarL;
- byte barRowR = 1; //0 or 1, lcd line to display progressBar-RCH
- byte barColR = 1; //0 or 1, lcd column to start progressBar
- byte barRowL = 1; //0 or 1, lcd line to display progressBar-LCH
- byte barColL = 1; //0 or 1, lcd column to start progressBar
- int posR = 0; //initialize progressbar position
- int posL = 0;
- int startR = 9; //start column of progress bar
- int startL = 0;
- //------------------------------------------------------------------------
- //------------------------------------------------------------------------
- byte myBarR[8] = { //custom character bitmap
- B11000,
- B11100,
- B11110,
- B01111,
- B01111,
- B11110,
- B11100,
- B11000,
- };
- byte myBarL[8] = { //custom character bitmap
- B00011,
- B00111,
- B01110,
- B11110,
- B11110,
- B01111,
- B00111,
- B00011,
- };
- void setup() { //setup function
- lcd.createChar(1,myBarR); //enable the created custom character
- lcd.createChar(2,myBarL);
- Serial.begin(9600);
- //------------------------------------------------------------------------
- lcd.begin(16,2);
- lcd.clear(); //clear lcd
- lcd.setCursor(0, 0);
- lcd.clear();
- delay(1000);
- lcd.print(" STEREO AUDIO ");
- lcd.setCursor(0, 1);
- lcd.print("POWER AMPLIFIER ");
- delay(3000);
- lcd.clear();
- delay(500);
- lcd.setCursor(0, 0);
- lcd.print("AUDIO AMPLIFIER ");
- delay(500);
- lcd.setCursor(8, 1);
- lcd.print("R");
- lcd.setCursor(7, 1);
- lcd.print("L");
- delay(1000);
- }
- //------------------------------------------------------------------------
- //------------------------------------------------------------------------
- void loop() { //main loop function
- //------------------------------------------------------------------------
- adc();
- }
- //------------------------------------------------------------------------
- //------------------------------------------------------------------------
- void adc(){ //adc function
- int Rval = analogRead(A0); //R-CH
- int Lval = analogRead(A1); //L-CH
- lcdBarR = map(Rval, 0, 1023, 0, 7); //map Rval to lcdBarR
- lcdBarL = map(Lval, 0, 1023, 0, 7); //map vLal to lcdBarL
- //------------------------------------------------------------------------
- lcdBarLevelR(); //display value on R-CH lcd progressBar
- lcdBarLevelL(); //display value on R-CH lcd progressBar
- //------------------------------------------------------------------------
- Serial.print("RVal = ");
- Serial.print(Rval);
- Serial.print("; LVal = ");
- Serial.println(Lval);
- delay(100);
- }
- //------------------------------------------------------------------------
- //------------------------------------------------------------------------
- void lcdBarLevelR(){ //lcd bar level function
- switch (lcdBarR)
- {
- case 0:;
- lcd.setCursor(startR,barRowR);
- lcd.print(" ");
- break;
- //--------------------------------------------------------------------
- case 1:;
- //lcd.createChar(1,myBarR);
- lcd.setCursor(startR,barRowR);//print custom characters all on 2nd line
- lcd.write(byte(1));
- lcd.setCursor((startR+1),barRowR);
- lcd.print(" ");
- break;
- //--------------------------------------------------------------------
- case 2:;
- posR = 11;
- for (int mycol = startR; mycol < posR; mycol++){
- //lcd.createChar(0,myBarR);
- lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
- lcd.write(byte(1));
- lcd.setCursor(posR,barRowR);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 3:;
- posR = 12;
- for (int mycol = startR; mycol < posR; mycol++){
- //lcd.createChar(0,myBarR);
- lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
- lcd.write(byte(1));
- lcd.setCursor(posR,barRowR);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 4:;
- posR = 13;
- for (int mycol = startR; mycol < posR; mycol++){
- //lcd.createChar(0,myBarR);
- lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
- lcd.write(byte(1));
- lcd.setCursor(posR,barRowR);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 5:;
- posR = 14;
- for (int mycol = startR; mycol < posR; mycol++){
- //lcd.createChar(0,myBarR);
- lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
- lcd.write(byte(1));
- lcd.setCursor(posR,barRowR);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 6:;
- posR = 15;
- for (int mycol = startR; mycol <= posR; mycol++){
- //lcd.createChar(0,myBarR);
- lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
- lcd.write(byte(1));
- lcd.setCursor(posR,barRowR);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 7:;
- posR = 16;
- for (int mycol = startR; mycol <= posR; mycol++){
- //lcd.createChar(0,myBarR);
- lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
- lcd.write(byte(1));
- }
- break;
- }
- }
- //-----------------------------------------------------------------------
- //-----------------------------------------------------------------------
- void lcdBarLevelL(){ //lcd bar level function
- switch (lcdBarL)
- {
- case 0:;
- lcd.setCursor(0,barRowL);
- lcd.print(" ");
- break;
- //--------------------------------------------------------------------
- case 1:;
- //lcd.createChar(0,myBarL);
- lcd.setCursor(6,barRowL);//print custom characters all on 2nd line
- lcd.write(byte(2));
- lcd.setCursor(0,barRowL);
- lcd.print(" ");
- break;
- //--------------------------------------------------------------------
- case 2:;
- posL = 7;
- for (int mycol = 5; mycol < posL; mycol++){
- //lcd.createChar(0,myBarL);
- lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
- lcd.write(byte(2));
- lcd.setCursor(0,barRowL);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 3:;
- posL = 7;
- for (int mycol = 4; mycol < posL; mycol++){
- //lcd.createChar(0,myBarL);
- lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
- lcd.write(byte(2));
- lcd.setCursor(0,barRowL);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 4:;
- posL = 7;
- for (int mycol = 3; mycol < posL; mycol++){
- //lcd.createChar(0,myBarL);
- lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
- lcd.write(byte(2));
- lcd.setCursor(0,barRowL);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 5:;
- posL = 7;
- for (int mycol = 2; mycol < posL; mycol++){
- //lcd.createChar(0,myBarL);
- lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
- lcd.write(byte(2));
- lcd.setCursor(0,barRowL);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 6:;
- posL = 7;
- for (int mycol = 1; mycol < posL; mycol++){
- //lcd.createChar(0,myBarL);
- lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
- lcd.write(byte(2));
- lcd.setCursor(0,barRowL);
- lcd.print(" ");
- }
- break;
- //--------------------------------------------------------------------
- case 7:;
- posL = 7;
- for (int mycol = 0; mycol < posL; mycol++){
- //lcd.createChar(0,myBarL);
- lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
- lcd.write(byte(2));
- }
- break;
- }
- }
- //-----------------------------------------------------------------------
- //-----------------------------------------------------------------------
Add Comment
Please, Sign In to add comment