Advertisement
RuiViana

Testa_Display

Mar 13th, 2017
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.66 KB | None | 0 0
  1. //#include <PCD8544.h>                      // Removi
  2. //--------------------------------------------------------------
  3. #include "U8glib.h"                         // Inclui
  4. // ajustada conforme o display utilizado.
  5. U8GLIB_ST7920_128X64_1X u8g(6, 5, 4 , 7); //Enable, RW, RS, RESET    Verifica se seu display está ligados nestes pinos
  6. int display = 1;
  7. //-----------------------------------------------------------------
  8.  
  9. #include <SoftwareSerial.h>
  10. SoftwareSerial mySerial(10, 11); // RX, TX
  11. // criando as variaveis na global
  12. //======================================================================================================
  13. char state = 1; // variável que guarda posição atual do menu
  14. int sensorValue1, sensorValue2, sensorValue3, sensorValue4, sensorValue5, sensorValue6, sensorValue7, sensorValue8; // entradas analogica de A0 a A7
  15. // porta Analogicas
  16. // A0 sensorValue1 pressão combustivel
  17. // A1 sensorValue2 pressão oleo
  18. // A2 sensorValue3 temperatura motor
  19. // A3 temperatura
  20. float tensao = 0; // variaveis da tensão da bateria
  21. byte detecta = 2; // porta de detecção de rpm
  22. int contador = 0; // contador de rpm
  23. // Dimensão do lcd (in pixels)...
  24. static const byte LCD_WIDTH = 84;
  25. static const byte LCD_HEIGHT = 48;
  26. // O número de linhas para o gráfico de temperatura...
  27. static const byte CHART_HEIGHT = 5;
  28. // Um símbolo de "graus" customizado...
  29. static const byte DEGREES_CHAR = 1;
  30. static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };
  31. // A bitmap graphic (10x2) of a thermometer...
  32. static const byte THERMO_WIDTH = 10;
  33. static const byte THERMO_HEIGHT = 2;
  34. static const byte thermometer[] = { 0x00, 0x00, 0x48, 0xfe, 0x01, 0xfe, 0x00, 0x02, 0x05, 0x02,
  35.                                     0x00, 0x00, 0x62, 0xff, 0xfe, 0xff, 0x60, 0x00, 0x00, 0x00
  36.                                   };
  37.  
  38. //static PCD8544 lcd;                               // Removi
  39. //----------------------------------------------
  40. void draw(void)
  41. {
  42.  /*
  43.  // graphic commands to redraw the complete screen should be placed here
  44.   u8g.setFont(u8g_font_unifont);
  45.   //u8g.setFont(u8g_font_osb21);
  46.   u8g.drawStr( 0, 22, "Hello World!");
  47.   */
  48.  
  49.       u8g.setFont(u8g_font_unifont);
  50.       u8g.drawStr( 0, 0, " BAT: ");
  51.      
  52.     //  u8g.drawStr( 0, 2, tensao); // tensão da bateria
  53.       u8g.drawStr( 8, 2, " V ");  
  54.       u8g.drawStr( 0, 4, "TANQUE: ");
  55.     //  u8g.drawStr( 8, 4, contador); // tensão da bateria
  56.       u8g.drawStr( 14, 4, " Lts");
  57.       u8g.drawStr( 0, 6, " TEMP:");  
  58.     //  u8g.drawStr( 8, 6, temperaturaEmCelsius, 1);
  59.     //  u8g.drawStr( 16, 6, " \001C ");
  60.      
  61. }
  62.   //----------------------------------------------
  63.   void setup()
  64.   {
  65.     // inicia o lcd nokia 5110
  66.     // lcd.begin(LCD_WIDTH, LCD_HEIGHT);                // Removi
  67.     Serial.begin(9600);
  68.     mySerial.begin(9600);
  69.  
  70.     // Registre o símbolo personalizado...
  71.     // lcd.createChar(DEGREES_CHAR, degrees_glyph);     // Removi
  72.  
  73.     // Botões
  74.  
  75.     pinMode(13, OUTPUT);
  76.     digitalWrite(13, HIGH);
  77.     pinMode(detecta, INPUT);
  78.     digitalWrite(detecta, HIGH);
  79.     contador = 0;
  80.     attachInterrupt(0, DETECTA, FALLING);
  81.     noInterrupts();
  82.  
  83.     // lcd.clear();                                         // Removi
  84.     //----------------------------------------------------------------------  Acrescentei
  85.     if ( u8g.getMode() == U8G_MODE_R3G3B2 )
  86.     {
  87.       u8g.setColorIndex(255);                         // white
  88.     }
  89.     else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
  90.     {
  91.       u8g.setColorIndex(3);                           // max intensity
  92.     }
  93.     else if ( u8g.getMode() == U8G_MODE_BW )
  94.     {
  95.       u8g.setColorIndex(1);                            // pixel on
  96.     }
  97.     else if ( u8g.getMode() == U8G_MODE_HICOLOR )
  98.     {
  99.       u8g.setHiColorByRGB(255, 255, 255);
  100.       //--------------------------------------------------------------------------
  101.     }
  102.     }
  103.     //-------------------------------------------
  104.     void loop()
  105.     {
  106.  
  107.       // processamento do contagiros
  108.       unsigned long tempo = millis();
  109.       while (tempo + 300 > millis())
  110.       {
  111.         interrupts();
  112.       }
  113.       digitalWrite(13, LOW);
  114.       int rpm = contador;
  115.       contador = contador * 100 ;
  116.  
  117.       // faz a varredura das portas analogicas
  118.       //==============================================================
  119.       sensorValue1 = analogRead(0); // analog input 0
  120.       sensorValue2 = analogRead(1); // analog input 1
  121.       sensorValue3 = analogRead(2); // analog input 2
  122.       sensorValue4 = analogRead(3); // analog input 3
  123.       sensorValue5 = analogRead(4); // analog input 4
  124.       sensorValue6 = analogRead(5); // analog input 5
  125.       sensorValue7 = analogRead(6); // analog input 6
  126.       sensorValue8 = analogRead(7); // analog input 7
  127.       // local onde manda os valores para a serial para tratamento no processing que sera enviada pelo bluetooh
  128.  
  129.       // tratamento da tensão da bateria para exibir no display
  130.       //==============================================================
  131.       tensao = sensorValue7 * 0.00488 ;
  132.       tensao = tensao * 4 ;
  133.  
  134.       //mySerial.print("ola");// porta serial bluetooth para enviar dados trocado pela serial
  135.  
  136.       // exibi na tela os valores de tensão e nivel combustivel
  137.       //==============================================================
  138.       float Combustivel = (sensorValue3 * 0.25390625 * 100.0 / 1024 ) - 1.0;
  139.       if (Combustivel > 8)
  140.       {
  141.         Combustivel = 0;
  142.       }
  143.       // tratamento da tensão da bateria para exibir no display
  144.       //===============================================================
  145.       float temperaturaEmCelsius = ( 5 * sensorValue2 * 100.0 / 1024);
  146.       if (temperaturaEmCelsius > 150)
  147.       {
  148.         temperaturaEmCelsius = 150.0;
  149.       }
  150.       //================================================================
  151.       /*
  152.         Removi
  153.         lcd.setCursor(0, LCD_HEIGHT/8 - THERMO_HEIGHT);
  154.         lcd.drawBitmap(thermometer, THERMO_WIDTH, THERMO_HEIGHT);
  155.         lcd.setCursor(0, 0);
  156.         lcd.print(" BAT: ");
  157.         lcd.print(tensao); // tensão da bateria
  158.         lcd.print(" V ");
  159.         lcd.setCursor(0, 2);
  160.         lcd.print("TANQUE: ");
  161.         lcd.print(contador); // tensão da bateria
  162.         lcd.print(" Lts");
  163.         lcd.print(" ");
  164.         lcd.setCursor(14, 4);
  165.         lcd.print(" TEMP:");
  166.         lcd.setCursor(14, 5);
  167.         lcd.print(temperaturaEmCelsius, 1);
  168.         lcd.print(" \001C ");
  169.       */
  170.       //----------------------------------------------------------------------  Acrescentei
  171.    
  172.       u8g.firstPage();
  173.       do
  174.         {
  175.         draw();
  176.         }
  177.         while ( u8g.nextPage() );
  178.  
  179.       //----------------------------------------------------------------------
  180.  
  181.       // local onde manda os valores para a serial para tratamento no processing
  182.       // apenas para depuração na serial
  183.       Serial.print(contador); // print rpm
  184.       Serial.print(","); // print ','
  185.       Serial.print(sensorValue1); // print sensor 1
  186.       Serial.print(","); // print ','
  187.       Serial.print(temperaturaEmCelsius); // print sensor 2
  188.       Serial.print(","); // print ','
  189.       Serial.print(Combustivel); // print sensor 3
  190.       Serial.print(",");
  191.       Serial.print(sensorValue4); // print sensor 4
  192.       Serial.print(",");
  193.       Serial.print(sensorValue5); // print sensor 5
  194.       Serial.print(",");
  195.       Serial.print(sensorValue6); // print sensor 6
  196.       Serial.print(",");
  197.       Serial.print(tensao); // print sensor 7
  198.       Serial.print(",");
  199.       Serial.println(sensorValue8); // print sensor 8  (println)
  200.     }
  201.     //========================================================================
  202.     void DETECTA()
  203.     {
  204.       contador ++;
  205.       Serial.print(contador);
  206.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement