Tarielect

Untitled

Jun 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.41 KB | None | 0 0
  1. //*************************************************************************
  2. //  Name     : StereoAudioAmpDisplayLCD                                   *
  3. //  Author   : Tarilayefa Edward                                          *
  4. //  Notice   : Tari Electronics & Embedded Systems (TEES), 2018.          *
  5. //           : tarielectronics@yahoo.com                                  *
  6. //           : tarielect.edward@gmail.com                                 *
  7. //           : +23408184754883,+23408062251186, Nigeria.                  *
  8. //           : https//:web.facebook.com/groups/teestraining/              *
  9. //           : https//:web.facebook.com/groups/picarduino/                *
  10. //  Date     : 26/05/2018                                                 *
  11. //  Version  : 1.0                                                        *
  12. //  Notes    : A program to display stereo audio output display on a 16x2 *
  13. //           : char lcd.                                                  *
  14. //  Reference: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx         *
  15. //  Compiler : avrgcc                                                     *
  16. //  IDE      : Arduino 1.8.5                                              *
  17. //  Target   : Atmega 328, Arduino Uno, Nano.                             *
  18. //*************************************************************************
  19.  
  20. #include <LiquidCrystal.h>  //add the lcd library
  21. LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //(rs,en,d4,d5,d6,d7)
  22. //#include <LiquidCrystal_SR.h> //add the 2/3 wire lcd library
  23. //LiquidCrystal_SR lcd(9,10);//(data,clock-2wire)or(data,clock,latch-3wire)
  24. //------------------------------------------------------------------------
  25. unsigned int lcdBarR;
  26. unsigned int lcdBarL;
  27. byte barRowR = 1; //0 or 1, lcd line to display progressBar-RCH
  28. byte barColR = 1; //0 or 1, lcd column to start progressBar
  29. byte barRowL = 1; //0 or 1, lcd line to display progressBar-LCH
  30. byte barColL = 1; //0 or 1, lcd column to start progressBar
  31. int posR = 0; //initialize progressbar position
  32. int posL = 0;
  33. int startR = 9;  //start column of progress bar
  34. int startL = 0;
  35. //------------------------------------------------------------------------
  36. //------------------------------------------------------------------------
  37. byte myBarR[8] = { //custom character bitmap
  38.     B11000,
  39.     B11100,
  40.     B11110,
  41.     B01111,
  42.     B01111,
  43.     B11110,
  44.     B11100,
  45.     B11000,
  46. };
  47.  
  48. byte myBarL[8] = { //custom character bitmap
  49.     B00011,
  50.     B00111,
  51.     B01110,
  52.     B11110,
  53.     B11110,
  54.     B01111,
  55.     B00111,
  56.     B00011,
  57. };
  58.  
  59. void setup() {  //setup function
  60.     lcd.createChar(1,myBarR); //enable the created custom character
  61.     lcd.createChar(2,myBarL);
  62.     Serial.begin(9600);
  63.     //------------------------------------------------------------------------
  64.     lcd.begin(16,2);
  65.     lcd.clear();  //clear lcd
  66.     lcd.setCursor(0, 0);
  67.     lcd.clear();
  68.     delay(1000);
  69.     lcd.print("  STEREO AUDIO  ");
  70.     lcd.setCursor(0, 1);
  71.     lcd.print("POWER AMPLIFIER ");
  72.     delay(3000);
  73.     lcd.clear();
  74.     delay(500);
  75.     lcd.setCursor(0, 0);
  76.     lcd.print("AUDIO AMPLIFIER ");
  77.     delay(500);
  78.     lcd.setCursor(8, 1);
  79.     lcd.print("R");
  80.     lcd.setCursor(7, 1);
  81.     lcd.print("L");
  82.     delay(1000);
  83. }
  84. //------------------------------------------------------------------------
  85. //------------------------------------------------------------------------
  86. void loop() {  //main loop function
  87.     //------------------------------------------------------------------------
  88.     adc();
  89. }
  90. //------------------------------------------------------------------------
  91. //------------------------------------------------------------------------
  92. void adc(){ //adc function
  93.     int Rval = analogRead(A0); //R-CH
  94.     int Lval = analogRead(A1); //L-CH
  95.     lcdBarR  = map(Rval, 0, 1023, 0, 7); //map Rval to lcdBarR
  96.     lcdBarL  = map(Lval, 0, 1023, 0, 7); //map vLal to lcdBarL
  97.     //------------------------------------------------------------------------
  98.     lcdBarLevelR();  //display value on R-CH lcd progressBar
  99.     lcdBarLevelL(); //display value on R-CH lcd progressBar
  100.     //------------------------------------------------------------------------
  101.     Serial.print("RVal = ");
  102.     Serial.print(Rval);
  103.     Serial.print("; LVal = ");
  104.     Serial.println(Lval);
  105.     delay(100);
  106. }
  107. //------------------------------------------------------------------------
  108. //------------------------------------------------------------------------
  109. void lcdBarLevelR(){ //lcd bar level function
  110.     switch (lcdBarR)
  111.     {
  112.     case 0:;
  113.         lcd.setCursor(startR,barRowR);
  114.         lcd.print("       ");
  115.         break;
  116.         //--------------------------------------------------------------------
  117.     case 1:;
  118.         //lcd.createChar(1,myBarR);
  119.         lcd.setCursor(startR,barRowR);//print custom characters all on 2nd line
  120.         lcd.write(byte(1));
  121.         lcd.setCursor((startR+1),barRowR);
  122.         lcd.print("      ");
  123.  
  124.         break;
  125.         //--------------------------------------------------------------------
  126.     case 2:;
  127.         posR = 11;
  128.         for (int mycol = startR; mycol < posR; mycol++){
  129.             //lcd.createChar(0,myBarR);
  130.             lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
  131.             lcd.write(byte(1));
  132.             lcd.setCursor(posR,barRowR);
  133.             lcd.print("     ");
  134.         }
  135.         break;
  136.         //--------------------------------------------------------------------
  137.     case 3:;
  138.         posR = 12;
  139.         for (int mycol = startR; mycol < posR; mycol++){
  140.             //lcd.createChar(0,myBarR);
  141.             lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
  142.             lcd.write(byte(1));
  143.             lcd.setCursor(posR,barRowR);
  144.             lcd.print("    ");
  145.         }
  146.         break;
  147.         //--------------------------------------------------------------------
  148.     case 4:;
  149.         posR = 13;
  150.         for (int mycol = startR; mycol < posR; mycol++){
  151.             //lcd.createChar(0,myBarR);
  152.             lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
  153.             lcd.write(byte(1));
  154.             lcd.setCursor(posR,barRowR);
  155.             lcd.print("   ");
  156.         }
  157.         break;
  158.         //--------------------------------------------------------------------
  159.     case 5:;
  160.         posR = 14;
  161.         for (int mycol = startR; mycol < posR; mycol++){
  162.             //lcd.createChar(0,myBarR);
  163.             lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
  164.             lcd.write(byte(1));
  165.             lcd.setCursor(posR,barRowR);
  166.             lcd.print("  ");
  167.         }
  168.         break;
  169.         //--------------------------------------------------------------------
  170.     case 6:;
  171.         posR = 15;
  172.         for (int mycol = startR; mycol <= posR; mycol++){
  173.             //lcd.createChar(0,myBarR);
  174.             lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
  175.             lcd.write(byte(1));
  176.             lcd.setCursor(posR,barRowR);
  177.             lcd.print(" ");
  178.         }
  179.         break;
  180.         //--------------------------------------------------------------------
  181.     case 7:;
  182.         posR = 16;
  183.         for (int mycol = startR; mycol <= posR; mycol++){
  184.             //lcd.createChar(0,myBarR);
  185.             lcd.setCursor(mycol,barRowR);//print custom characters all on 2nd line
  186.             lcd.write(byte(1));
  187.         }
  188.         break; 
  189.     }
  190. }
  191. //-----------------------------------------------------------------------
  192. //-----------------------------------------------------------------------
  193. void lcdBarLevelL(){ //lcd bar level function
  194.     switch (lcdBarL)
  195.     {
  196.     case 0:;
  197.         lcd.setCursor(0,barRowL);
  198.         lcd.print("       ");
  199.         break;
  200.         //--------------------------------------------------------------------
  201.     case 1:;
  202.         //lcd.createChar(0,myBarL);
  203.         lcd.setCursor(6,barRowL);//print custom characters all on 2nd line
  204.         lcd.write(byte(2));
  205.         lcd.setCursor(0,barRowL);
  206.         lcd.print("      ");
  207.  
  208.         break;
  209.         //--------------------------------------------------------------------
  210.     case 2:;
  211.         posL = 7;
  212.         for (int mycol = 5; mycol < posL; mycol++){
  213.             //lcd.createChar(0,myBarL);
  214.             lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
  215.             lcd.write(byte(2));
  216.             lcd.setCursor(0,barRowL);
  217.             lcd.print("     ");
  218.         }
  219.         break;
  220.         //--------------------------------------------------------------------
  221.     case 3:;
  222.         posL = 7;
  223.         for (int mycol = 4; mycol < posL; mycol++){
  224.             //lcd.createChar(0,myBarL);
  225.             lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
  226.             lcd.write(byte(2));
  227.             lcd.setCursor(0,barRowL);
  228.             lcd.print("    ");
  229.         }
  230.         break;
  231.         //--------------------------------------------------------------------
  232.     case 4:;
  233.         posL = 7;
  234.         for (int mycol = 3; mycol < posL; mycol++){
  235.             //lcd.createChar(0,myBarL);
  236.             lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
  237.             lcd.write(byte(2));
  238.             lcd.setCursor(0,barRowL);
  239.             lcd.print("   ");
  240.         }
  241.         break;
  242.         //--------------------------------------------------------------------
  243.     case 5:;
  244.         posL = 7;
  245.         for (int mycol = 2; mycol < posL; mycol++){
  246.             //lcd.createChar(0,myBarL);
  247.             lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
  248.             lcd.write(byte(2));
  249.             lcd.setCursor(0,barRowL);
  250.             lcd.print("  ");
  251.         }
  252.         break;
  253.         //--------------------------------------------------------------------
  254.     case 6:;
  255.         posL = 7;
  256.         for (int mycol = 1; mycol < posL; mycol++){
  257.             //lcd.createChar(0,myBarL);
  258.             lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
  259.             lcd.write(byte(2));
  260.             lcd.setCursor(0,barRowL);
  261.             lcd.print(" ");
  262.         }
  263.         break;
  264.         //--------------------------------------------------------------------
  265.     case 7:;
  266.         posL = 7;
  267.         for (int mycol = 0; mycol < posL; mycol++){
  268.             //lcd.createChar(0,myBarL);
  269.             lcd.setCursor(mycol,barRowL);//print custom characters all on 2nd line
  270.             lcd.write(byte(2));
  271.         }
  272.         break; 
  273.     }
  274. }
  275. //-----------------------------------------------------------------------
  276. //-----------------------------------------------------------------------
Add Comment
Please, Sign In to add comment