Advertisement
RuiViana

Matriz_SHT10,ino

Sep 8th, 2020
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.61 KB | None | 0 0
  1. /*
  2.    Nome do Projeto:  Matrix_8x24_SHT10_V01
  3.    Nome do Aquivo:   Matrix_8x24_SHT10_V01.ino
  4.    Dependências:     Sensirion.h      Biblioteca de SHT10
  5.    MCU:              ATmega
  6.    Board:            Arduino Uno/Mega/Mini
  7.    Compilador        N/A
  8.    IDE:              Arduino IDE 1.6.6
  9.    Hardware:         Arduino UNO/MEGA/Mini
  10.    Escrito por:      Rui Viana
  11.    Data:             21/09/2016
  12.    Uso:              Didático
  13.    Desenhos          Matrix_8x24_SHT10_V01.png
  14.    Copyright @       N/A
  15.  
  16.    Este programa é software livre;
  17.    e é distribuído na esperança que possa ser útil, mas SEM QUALQUER GARANTIA;
  18.    mesmo sem a garantia implícita de COMERCIALIZAÇÃO ou ADEQUAÇÃO A UM DETERMINADO FIM.
  19.  
  20.    REVISIONS: (latest entry first)
  21.     21/09/2016   -   Matrix_8x24_SHT10_V01.ino - First release
  22.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23.    Descrição:
  24.  
  25.    Este código utiliza a biblioteca DHT.h para ler sensores de umidade e de temperatura.
  26.    Le os valores do SHT10 e mostra em uma matriz de LED de 8x24.
  27.    os caracteres são no formato 7 x 5.
  28.    As funções de display copiei do link:
  29.    http://www.instructables.com/id/48x8-SCROLLING-MATRIX-LED-DISPLAY-USING-ARDUINO-CO/?ALLSTEPS
  30.  
  31.   Acrescentei os caracteres minúsculos e símbolos, e os comandos que medem a temperatura e
  32.   umidade, transformando-as em string e depois em array.
  33.   Em seguinda enviando-as para o display.
  34.  
  35.   Quero aqui agradecer o esforço do Celso Eiju Ito,
  36.   pois o funcionamento das funções de mostrar a temperatura em float só foi possível com a ajuda dele.
  37.  
  38.   Coloquei um LED piscando em D4 para monitor o Arduino
  39.   Modifiquei as saídas para os 74HC595
  40.  
  41. */
  42.  
  43. //************  Variaveis e constantes  ************
  44. #include <Sensirion.h>                        // Inclui a biblioteca do SHT10
  45. #define LED 4                                 // pino para o LED
  46.  
  47. #define dataPin  2
  48. #define clockPin 3
  49. float temperature;
  50. float humidity;
  51. float dewpoint;
  52. Sensirion tempSensor = Sensirion(dataPin, clockPin);
  53.  
  54. int x;
  55. int y;
  56.  
  57. int latchPin1 = 6;   //Arduino pin connected to blue 12 RCLK of 74HC595
  58. int clockPin1 = 7;   //Arduino pin connected to green 11 SRCLK of 74HC595
  59. int dataPin1  = 8;   //Arduino pin connected to violet 14 SER of 74HC595
  60.  
  61. //-- Rows (Positive Anodes) --
  62. int latchPin2 = 10;  //Arduino pin connected to yellow Latch 12 RCLK of 74HC595
  63. int clockPin2 = 11;  //Arduino pin connected to white Clock 11 SRCLK of 74HC595
  64. int dataPin2  = 9;   //Arduino pin connected to grey Data 14 SER of 74HC595
  65.  
  66. //=== B I T M A P ===
  67. //Bits in this array represents one LED of the matrix
  68. // 8 is # of rows, 7 is # of LED matrix we have
  69. byte bitmap[8][4]; // Change the 7 to however many matrices you want to use.
  70. int numZones = sizeof(bitmap) / 8;
  71. int maxZoneIndex = numZones - 1;
  72. int numCols = numZones * 8;
  73.  
  74. const byte alphabets[][5] = {
  75.   {0, 0, 0, 0, 0},                   // Espaço
  76.   {0x00, 0x00, 0xFA, 0x00, 0x00},    // !
  77.   {0x00, 0xE0, 0x00, 0xE0, 0x00},    // "
  78.   {0x28, 0xFE, 0x28, 0xFE, 0x28},    // #
  79.   {0x24, 0x54, 0xFE, 0x54, 0x48},    // $
  80.   {0xC4, 0xC8, 0x10, 0x26, 0x46},    // %
  81.   {0x6C, 0x92, 0xAA, 0x44, 0x0A},    // &
  82.   {0x00, 0xA0, 0xC0, 0x00, 0x00},    // '
  83.   {0x00, 0x38, 0x44, 0x82, 0x00},    // (
  84.   {0x00, 0x82, 0x44, 0x38, 0x00},    // )
  85.   {0x10, 0x54, 0x38, 0x54, 0x10},    // *
  86.   {0x10, 0x10, 0x7C, 0x10, 0x10},    // +
  87.   {0x00, 0x0A, 0x0C, 0x00, 0x00},    // ,
  88.   {0x10, 0x10, 0x10, 0x10, 0x10},    // -
  89.   {0x00, 0x06, 0x06, 0x00, 0x00},    // .
  90.   {0x04, 0x08, 0x10, 0x20, 0x40},    // /
  91.   {0x7C, 0x8A, 0x92, 0xA2, 0x7C},    // 0
  92.   {0x00, 0x42, 0xFE, 0x02, 0x00},    // 1
  93.   {0x42, 0x86, 0x8A, 0x92, 0x62},    // 2
  94.   {0x84, 0x82, 0xA2, 0xD2, 0x8C},    // 3
  95.   {0x18, 0x28, 0x48, 0xFE, 0x08},    // 4
  96.   {0xE4, 0xA2, 0xA2, 0xA2, 0x9C},    // 5
  97.   {0x3C, 0x52, 0x92, 0x92, 0xC},     // 6
  98.   {0x80, 0x8E, 0x90, 0xA0, 0xC0},    // 7
  99.   {0x6C, 0x92, 0x92, 0x92, 0x6C},    // 8
  100.   {0x60, 0x92, 0x92, 0x94, 0x78},    // 9
  101.  
  102.   {0x00, 0x6C, 0x6C, 0x00, 0x00},    // :
  103.   {0x00, 0x6A, 0x6C, 0x00, 0x00},    // ;
  104.   {0x00, 0x10, 0x28, 0x44, 0x82},    // <
  105.   {0x28, 0x28, 0x28, 0x28, 0x28},    // =
  106.   {0x82, 0x44, 0x28, 0x10, 0x00},    // >
  107.   {0x40, 0x80, 0x8A, 0x90, 0x60},    // ?
  108.   {0x4C, 0x92, 0x9E, 0x82, 0x7C},    // @
  109.   {0x7E, 0x88, 0x88, 0x88, 0x7E},    // A
  110.   {0xFE, 0x92, 0x92, 0x92, 0x6C},    // B
  111.   {0x7C, 0x82, 0x82, 0x82, 0x44},    // C
  112.   {0xFE, 0x82, 0x82, 0x44, 0x38},    // D
  113.   {0xFE, 0x92, 0x92, 0x92, 0x82},    // E
  114.   {0xFE, 0x90, 0x90, 0x80, 0x80},    // F
  115.   {0x7C, 0x82, 0x82, 0x8A, 0x4C},    // G
  116.   {0xFE, 0x10, 0x10, 0x10, 0xFE},    // H
  117.   {0x00, 0x82, 0xFE, 0x82, 0x00},    // I
  118.   {0x04, 0x02, 0x82, 0xFC, 0x80},    // J
  119.   {0xFE, 0x10, 0x28, 0x44, 0x82},    // K
  120.   {0xFE, 0x02, 0x02, 0x02, 0x02},    // L
  121.   {0xFE, 0x40, 0x20, 0x40, 0xFE},    // M
  122.   {0xFE, 0x20, 0x10, 0x08, 0xFE},    // N
  123.   {0x7C, 0x82, 0x82, 0x82, 0x7C},    // O
  124.   {0xFE, 0x90, 0x90, 0x90, 0x60},    // P
  125.   {0x7C, 0x82, 0x8A, 0x84, 0x7A},    // Q
  126.   {0xFE, 0x90, 0x98, 0x94, 0x62},    // R
  127.   {0x62, 0x92, 0x92, 0x92, 0x8C},    // S
  128.   {0x80, 0x80, 0xFE, 0x80, 0x80},    // T
  129.   {0xFC, 0x02, 0x02, 0x02, 0xFC},    // U
  130.   {0xF8, 0x04, 0x02, 0x04, 0xF8},    // V
  131.   {0xFE, 0x04, 0x18, 0x04, 0xFE},    // W
  132.   {0xC6, 0x28, 0x10, 0x28, 0xC6},    // X
  133.   {0xC0, 0x20, 0x1E, 0x20, 0xC0},    // Y
  134.   {0x86, 0x8A, 0x92, 0xA2, 0xC2},    // Z
  135.  
  136.   {0x00, 0x00, 0xFE, 0x82, 0x82},    // [
  137.   {0x40, 0x20, 0x10, 0x08, 0x04},    // \
  138.   {0x82, 0x82, 0xFE, 0x00, 0x00},    // ]
  139.   {0x20, 0x40, 0x80, 0x40, 0x20},    // ^
  140.   {0x02, 0x02, 0x02, 0x02, 0x02},    // _
  141.   {0x00, 0x80, 0x40, 0x20, 0x00},    // `
  142.   {0x00, 0x00, 0x00, 0x00, 0x00},    // null
  143.  
  144.   {0x04, 0x2A, 0x2A, 0x2A, 0x1E},    // a
  145.   {0xFE, 0x12, 0x22, 0x22, 0x1C},    // b
  146.   {0x1C, 0x22, 0x22, 0x22, 0x04},    // c
  147.   {0x1C, 0x22, 0x22, 0x12, 0xFE},    // d
  148.   {0x1C, 0x2A, 0x2A, 0x2A, 0x18},    // e
  149.   {0x10, 0x7E, 0x90, 0x80, 0x40},    // f
  150.   {0x10, 0x28, 0x2A, 0x2A, 0x3C},    // g
  151.   {0xFE, 0x10, 0x20, 0x20, 0x1E},    // h
  152.   {0x00, 0x22, 0xBE, 0x02, 0x00},    // i
  153.   {0x04, 0x02, 0x22, 0xBC, 0x00},    // j
  154.   {0x00, 0xFE, 0x08, 0x14, 0x22},    // k
  155.   {0x00, 0x82, 0xFE, 0x02, 0x00},    // l
  156.   {0x3E, 0x20, 0x18, 0x20, 0x1E},    // m
  157.   {0x3E, 0x10, 0x20, 0x20, 0x1E},    // n
  158.   {0x1C, 0x22, 0x22, 0x22, 0x1C},    // o
  159.   {0x3E, 0x28, 0x28, 0x28, 0x10},    // p
  160.   {0x10, 0x28, 0x28, 0x18, 0x3E},    // q
  161.   {0x3E, 0x10, 0x20, 0x20, 0x10},    // r
  162.   {0x12, 0x2A, 0x2A, 0x2A, 0x04},    // s
  163.   {0x20, 0xFC, 0x22, 0x02, 0x04},    // t
  164.   {0x3C, 0x02, 0x02, 0x04, 0x3E},    // u
  165.   {0x38, 0x04, 0x02, 0x04, 0x38},    // v
  166.   {0x3C, 0x02, 0x0C, 0x02, 0x3C},    // w
  167.   {0x22, 0x14, 0x08, 0x14, 0x22},    // x
  168.   {0x30, 0x0A, 0x0A, 0x0A, 0x3C},    // y
  169.   {0x22, 0x26, 0x2A, 0x32, 0x22},    // z
  170.  
  171.   {0x00, 0x10, 0x6C, 0x82, 0x00},    // {
  172.   {0x00, 0x00, 0xFE, 0x00, 0x00},    // |
  173.   {0x00, 0x82, 0x6C, 0x10, 0x00},    // }
  174.   {0x10, 0x10, 0x54, 0x38, 0x10},    //->
  175.   {0x10, 0x38, 0x54, 0x10, 0x10},    //<-
  176. };
  177. char msg[17] ;
  178. //************************  setup() ***********************
  179. void setup()
  180. {
  181.   Serial.begin(9600);
  182. //  dht.begin();                                 // inicializa o Sensor
  183.   pinMode(LED, OUTPUT);                         // Saída para monitor funcionamento do Arduino
  184.   pinMode(latchPin1, OUTPUT);
  185.   pinMode(clockPin1, OUTPUT);
  186.   pinMode(dataPin1, OUTPUT);
  187.  
  188.   pinMode(latchPin2, OUTPUT);
  189.   pinMode(clockPin2, OUTPUT);
  190.   pinMode(dataPin2, OUTPUT);
  191.  
  192.   //-- Clear bitmap --
  193.   for (int row = 0; row > 8; row++)
  194.   {
  195.     for (int zone = 0; zone <= maxZoneIndex; zone++)
  196.     {
  197.       bitmap[row][zone] = 0;
  198.     }
  199.   }
  200. }
  201. //************************  RefreshDisplay() ***********************
  202. // This routine takes whatever we've setup in the bitmap array and display it on the matrix
  203. void RefreshDisplay()
  204. {
  205.   for (int row = 0; row < 8; row++)
  206.   {
  207.     int rowbit = 1 << row;
  208.     digitalWrite(latchPin2, LOW);  //Hold latchPin LOW for as long as we're transmitting data
  209.     shiftOut(dataPin2, clockPin2, MSBFIRST, rowbit);   //Transmit data
  210.     //-- Start sending column bytes --
  211.     digitalWrite(latchPin1, LOW);  //Hold latchPin LOW for as long as we're transmitting data
  212.     //-- Shift out to each matrix (zone is 8 columns represented by one matrix)
  213.     for (int zone = maxZoneIndex; zone >= 0; zone--)
  214.     {
  215.       shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
  216.     }
  217.     //-- Done sending Column bytes, flip both latches at once to eliminate flicker
  218.     digitalWrite(latchPin1, HIGH);
  219.     digitalWrite(latchPin2, HIGH);
  220.     //-- Wait a little bit to let humans see what we've pushed out onto the matrix --
  221.     delayMicroseconds(50);
  222.   }
  223. }
  224. //************************  Plot() ***********************
  225. // Converts row and colum to actual bitmap bit and turn it off/on
  226. void Plot(int col, int row, bool isOn)
  227. {
  228.   int zone = col / 8;
  229.   //   int colBitIndex = x % 8;
  230.   //   byte colBit = 1 << colBitIndex;
  231.   byte colBit = 1;
  232.   if (isOn)
  233.     bitmap[row][zone] =  bitmap[y][zone] | colBit;
  234.   else
  235.     bitmap[row][zone] =  bitmap[y][zone] & (~colBit);
  236. }
  237. //************************  AlphabetSoup() ***********************
  238. // Plot each character of the message one column at a time, updated the display, shift bitmap left.
  239. void AlphabetSoup()
  240. {
  241.   //    char msg[] = "YOUR TEXT ";   // Era aqui, mudei para o ínicio
  242.   for (int charIndex = 0; charIndex < (sizeof(msg) - 1); charIndex++)
  243.   {
  244.     int alphabetIndex = msg[charIndex] - 0x20;      // Era "@", mudei para 0x20 para aumentar o inicio da tabela
  245.     if (alphabetIndex < 0) alphabetIndex = 0;
  246.     //-- Draw one character of the message --
  247.     for (int col = 0; col < 6; col++)
  248.     {
  249.       for (int row = 0; row < 8; row++)
  250.       {
  251.         bool isOn = 0;
  252.         if (col < 5) isOn = bitRead( alphabets[alphabetIndex][col], 7 - row ) == 1;
  253.         Plot( numCols - 1, row, isOn);
  254.       }
  255.       //-- The more times you repeat this loop, the slower we would scroll --
  256.       for (int refreshCount = 0; refreshCount < 7; refreshCount++) //change  this value to vary speed
  257.         RefreshDisplay();
  258.       //-- Shift the bitmap one column to left --
  259.       for (int row = 0; row < 8; row++)
  260.       {
  261.         for (int zone = 0; zone < numZones; zone++)
  262.         {
  263.           bitmap[row][zone] = bitmap[row][zone] >> 1;
  264.           // Roll over lowest bit from the next zone as highest bit of this zone.
  265.           if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7,
  266.                                               bitRead(bitmap[row][zone + 1], 0));
  267.         }
  268.       }
  269.     }
  270.   }
  271. }
  272. //*****************************  loop() **************************
  273. void loop()
  274. {
  275.   float Celso;                                   // Varialvel para guardar valor de temperatura
  276.   // Varialvel em homengem ao Celso kkkkkk
  277.   int humidade;                                  // Varialvel para guardar valor de umidade
  278.   String Display;                                // Varialvel tipo string para guardar o texto para o display
  279.    tempSensor.measure(&temperature, &humidity, &dewpoint);
  280.   Display = "C:";                                // C: no texto
  281.   Display += temperature;                              // valor da temperatura no texto
  282.   Display += " H:";                              // H: no texto
  283.   Display += humidity;                           // valor da umidade no texto
  284.   Display.toCharArray(msg, 13);                  // string para array
  285.   digitalWrite(LED, HIGH);                       // turn the LED on (HIGH is the voltage level)
  286.   AlphabetSoup();                                // chama rotina para display
  287.   digitalWrite(LED, LOW);                        // turn the LED on (LOW is the voltage level)
  288. }
  289.  
  290.  
  291.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement