Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Nome do Projeto: Matrix_8x24_SHT10_V01
- Nome do Aquivo: Matrix_8x24_SHT10_V01.ino
- Dependências: Sensirion.h Biblioteca de SHT10
- MCU: ATmega
- Board: Arduino Uno/Mega/Mini
- Compilador N/A
- IDE: Arduino IDE 1.6.6
- Hardware: Arduino UNO/MEGA/Mini
- Escrito por: Rui Viana
- Data: 21/09/2016
- Uso: Didático
- Desenhos Matrix_8x24_SHT10_V01.png
- Copyright @ N/A
- Este programa é software livre;
- e é distribuído na esperança que possa ser útil, mas SEM QUALQUER GARANTIA;
- mesmo sem a garantia implícita de COMERCIALIZAÇÃO ou ADEQUAÇÃO A UM DETERMINADO FIM.
- REVISIONS: (latest entry first)
- 21/09/2016 - Matrix_8x24_SHT10_V01.ino - First release
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Descrição:
- Este código utiliza a biblioteca DHT.h para ler sensores de umidade e de temperatura.
- Le os valores do SHT10 e mostra em uma matriz de LED de 8x24.
- os caracteres são no formato 7 x 5.
- As funções de display copiei do link:
- http://www.instructables.com/id/48x8-SCROLLING-MATRIX-LED-DISPLAY-USING-ARDUINO-CO/?ALLSTEPS
- Acrescentei os caracteres minúsculos e símbolos, e os comandos que medem a temperatura e
- umidade, transformando-as em string e depois em array.
- Em seguinda enviando-as para o display.
- Quero aqui agradecer o esforço do Celso Eiju Ito,
- pois o funcionamento das funções de mostrar a temperatura em float só foi possível com a ajuda dele.
- Coloquei um LED piscando em D4 para monitor o Arduino
- Modifiquei as saídas para os 74HC595
- */
- //************ Variaveis e constantes ************
- #include <Sensirion.h> // Inclui a biblioteca do SHT10
- #define LED 4 // pino para o LED
- #define dataPin 2
- #define clockPin 3
- float temperature;
- float humidity;
- float dewpoint;
- Sensirion tempSensor = Sensirion(dataPin, clockPin);
- int x;
- int y;
- int latchPin1 = 6; //Arduino pin connected to blue 12 RCLK of 74HC595
- int clockPin1 = 7; //Arduino pin connected to green 11 SRCLK of 74HC595
- int dataPin1 = 8; //Arduino pin connected to violet 14 SER of 74HC595
- //-- Rows (Positive Anodes) --
- int latchPin2 = 10; //Arduino pin connected to yellow Latch 12 RCLK of 74HC595
- int clockPin2 = 11; //Arduino pin connected to white Clock 11 SRCLK of 74HC595
- int dataPin2 = 9; //Arduino pin connected to grey Data 14 SER of 74HC595
- //=== B I T M A P ===
- //Bits in this array represents one LED of the matrix
- // 8 is # of rows, 7 is # of LED matrix we have
- byte bitmap[8][4]; // Change the 7 to however many matrices you want to use.
- int numZones = sizeof(bitmap) / 8;
- int maxZoneIndex = numZones - 1;
- int numCols = numZones * 8;
- const byte alphabets[][5] = {
- {0, 0, 0, 0, 0}, // Espaço
- {0x00, 0x00, 0xFA, 0x00, 0x00}, // !
- {0x00, 0xE0, 0x00, 0xE0, 0x00}, // "
- {0x28, 0xFE, 0x28, 0xFE, 0x28}, // #
- {0x24, 0x54, 0xFE, 0x54, 0x48}, // $
- {0xC4, 0xC8, 0x10, 0x26, 0x46}, // %
- {0x6C, 0x92, 0xAA, 0x44, 0x0A}, // &
- {0x00, 0xA0, 0xC0, 0x00, 0x00}, // '
- {0x00, 0x38, 0x44, 0x82, 0x00}, // (
- {0x00, 0x82, 0x44, 0x38, 0x00}, // )
- {0x10, 0x54, 0x38, 0x54, 0x10}, // *
- {0x10, 0x10, 0x7C, 0x10, 0x10}, // +
- {0x00, 0x0A, 0x0C, 0x00, 0x00}, // ,
- {0x10, 0x10, 0x10, 0x10, 0x10}, // -
- {0x00, 0x06, 0x06, 0x00, 0x00}, // .
- {0x04, 0x08, 0x10, 0x20, 0x40}, // /
- {0x7C, 0x8A, 0x92, 0xA2, 0x7C}, // 0
- {0x00, 0x42, 0xFE, 0x02, 0x00}, // 1
- {0x42, 0x86, 0x8A, 0x92, 0x62}, // 2
- {0x84, 0x82, 0xA2, 0xD2, 0x8C}, // 3
- {0x18, 0x28, 0x48, 0xFE, 0x08}, // 4
- {0xE4, 0xA2, 0xA2, 0xA2, 0x9C}, // 5
- {0x3C, 0x52, 0x92, 0x92, 0xC}, // 6
- {0x80, 0x8E, 0x90, 0xA0, 0xC0}, // 7
- {0x6C, 0x92, 0x92, 0x92, 0x6C}, // 8
- {0x60, 0x92, 0x92, 0x94, 0x78}, // 9
- {0x00, 0x6C, 0x6C, 0x00, 0x00}, // :
- {0x00, 0x6A, 0x6C, 0x00, 0x00}, // ;
- {0x00, 0x10, 0x28, 0x44, 0x82}, // <
- {0x28, 0x28, 0x28, 0x28, 0x28}, // =
- {0x82, 0x44, 0x28, 0x10, 0x00}, // >
- {0x40, 0x80, 0x8A, 0x90, 0x60}, // ?
- {0x4C, 0x92, 0x9E, 0x82, 0x7C}, // @
- {0x7E, 0x88, 0x88, 0x88, 0x7E}, // A
- {0xFE, 0x92, 0x92, 0x92, 0x6C}, // B
- {0x7C, 0x82, 0x82, 0x82, 0x44}, // C
- {0xFE, 0x82, 0x82, 0x44, 0x38}, // D
- {0xFE, 0x92, 0x92, 0x92, 0x82}, // E
- {0xFE, 0x90, 0x90, 0x80, 0x80}, // F
- {0x7C, 0x82, 0x82, 0x8A, 0x4C}, // G
- {0xFE, 0x10, 0x10, 0x10, 0xFE}, // H
- {0x00, 0x82, 0xFE, 0x82, 0x00}, // I
- {0x04, 0x02, 0x82, 0xFC, 0x80}, // J
- {0xFE, 0x10, 0x28, 0x44, 0x82}, // K
- {0xFE, 0x02, 0x02, 0x02, 0x02}, // L
- {0xFE, 0x40, 0x20, 0x40, 0xFE}, // M
- {0xFE, 0x20, 0x10, 0x08, 0xFE}, // N
- {0x7C, 0x82, 0x82, 0x82, 0x7C}, // O
- {0xFE, 0x90, 0x90, 0x90, 0x60}, // P
- {0x7C, 0x82, 0x8A, 0x84, 0x7A}, // Q
- {0xFE, 0x90, 0x98, 0x94, 0x62}, // R
- {0x62, 0x92, 0x92, 0x92, 0x8C}, // S
- {0x80, 0x80, 0xFE, 0x80, 0x80}, // T
- {0xFC, 0x02, 0x02, 0x02, 0xFC}, // U
- {0xF8, 0x04, 0x02, 0x04, 0xF8}, // V
- {0xFE, 0x04, 0x18, 0x04, 0xFE}, // W
- {0xC6, 0x28, 0x10, 0x28, 0xC6}, // X
- {0xC0, 0x20, 0x1E, 0x20, 0xC0}, // Y
- {0x86, 0x8A, 0x92, 0xA2, 0xC2}, // Z
- {0x00, 0x00, 0xFE, 0x82, 0x82}, // [
- {0x40, 0x20, 0x10, 0x08, 0x04}, // \
- {0x82, 0x82, 0xFE, 0x00, 0x00}, // ]
- {0x20, 0x40, 0x80, 0x40, 0x20}, // ^
- {0x02, 0x02, 0x02, 0x02, 0x02}, // _
- {0x00, 0x80, 0x40, 0x20, 0x00}, // `
- {0x00, 0x00, 0x00, 0x00, 0x00}, // null
- {0x04, 0x2A, 0x2A, 0x2A, 0x1E}, // a
- {0xFE, 0x12, 0x22, 0x22, 0x1C}, // b
- {0x1C, 0x22, 0x22, 0x22, 0x04}, // c
- {0x1C, 0x22, 0x22, 0x12, 0xFE}, // d
- {0x1C, 0x2A, 0x2A, 0x2A, 0x18}, // e
- {0x10, 0x7E, 0x90, 0x80, 0x40}, // f
- {0x10, 0x28, 0x2A, 0x2A, 0x3C}, // g
- {0xFE, 0x10, 0x20, 0x20, 0x1E}, // h
- {0x00, 0x22, 0xBE, 0x02, 0x00}, // i
- {0x04, 0x02, 0x22, 0xBC, 0x00}, // j
- {0x00, 0xFE, 0x08, 0x14, 0x22}, // k
- {0x00, 0x82, 0xFE, 0x02, 0x00}, // l
- {0x3E, 0x20, 0x18, 0x20, 0x1E}, // m
- {0x3E, 0x10, 0x20, 0x20, 0x1E}, // n
- {0x1C, 0x22, 0x22, 0x22, 0x1C}, // o
- {0x3E, 0x28, 0x28, 0x28, 0x10}, // p
- {0x10, 0x28, 0x28, 0x18, 0x3E}, // q
- {0x3E, 0x10, 0x20, 0x20, 0x10}, // r
- {0x12, 0x2A, 0x2A, 0x2A, 0x04}, // s
- {0x20, 0xFC, 0x22, 0x02, 0x04}, // t
- {0x3C, 0x02, 0x02, 0x04, 0x3E}, // u
- {0x38, 0x04, 0x02, 0x04, 0x38}, // v
- {0x3C, 0x02, 0x0C, 0x02, 0x3C}, // w
- {0x22, 0x14, 0x08, 0x14, 0x22}, // x
- {0x30, 0x0A, 0x0A, 0x0A, 0x3C}, // y
- {0x22, 0x26, 0x2A, 0x32, 0x22}, // z
- {0x00, 0x10, 0x6C, 0x82, 0x00}, // {
- {0x00, 0x00, 0xFE, 0x00, 0x00}, // |
- {0x00, 0x82, 0x6C, 0x10, 0x00}, // }
- {0x10, 0x10, 0x54, 0x38, 0x10}, //->
- {0x10, 0x38, 0x54, 0x10, 0x10}, //<-
- };
- char msg[17] ;
- //************************ setup() ***********************
- void setup()
- {
- Serial.begin(9600);
- // dht.begin(); // inicializa o Sensor
- pinMode(LED, OUTPUT); // Saída para monitor funcionamento do Arduino
- pinMode(latchPin1, OUTPUT);
- pinMode(clockPin1, OUTPUT);
- pinMode(dataPin1, OUTPUT);
- pinMode(latchPin2, OUTPUT);
- pinMode(clockPin2, OUTPUT);
- pinMode(dataPin2, OUTPUT);
- //-- Clear bitmap --
- for (int row = 0; row > 8; row++)
- {
- for (int zone = 0; zone <= maxZoneIndex; zone++)
- {
- bitmap[row][zone] = 0;
- }
- }
- }
- //************************ RefreshDisplay() ***********************
- // This routine takes whatever we've setup in the bitmap array and display it on the matrix
- void RefreshDisplay()
- {
- for (int row = 0; row < 8; row++)
- {
- int rowbit = 1 << row;
- digitalWrite(latchPin2, LOW); //Hold latchPin LOW for as long as we're transmitting data
- shiftOut(dataPin2, clockPin2, MSBFIRST, rowbit); //Transmit data
- //-- Start sending column bytes --
- digitalWrite(latchPin1, LOW); //Hold latchPin LOW for as long as we're transmitting data
- //-- Shift out to each matrix (zone is 8 columns represented by one matrix)
- for (int zone = maxZoneIndex; zone >= 0; zone--)
- {
- shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
- }
- //-- Done sending Column bytes, flip both latches at once to eliminate flicker
- digitalWrite(latchPin1, HIGH);
- digitalWrite(latchPin2, HIGH);
- //-- Wait a little bit to let humans see what we've pushed out onto the matrix --
- delayMicroseconds(50);
- }
- }
- //************************ Plot() ***********************
- // Converts row and colum to actual bitmap bit and turn it off/on
- void Plot(int col, int row, bool isOn)
- {
- int zone = col / 8;
- // int colBitIndex = x % 8;
- // byte colBit = 1 << colBitIndex;
- byte colBit = 1;
- if (isOn)
- bitmap[row][zone] = bitmap[y][zone] | colBit;
- else
- bitmap[row][zone] = bitmap[y][zone] & (~colBit);
- }
- //************************ AlphabetSoup() ***********************
- // Plot each character of the message one column at a time, updated the display, shift bitmap left.
- void AlphabetSoup()
- {
- // char msg[] = "YOUR TEXT "; // Era aqui, mudei para o ínicio
- for (int charIndex = 0; charIndex < (sizeof(msg) - 1); charIndex++)
- {
- int alphabetIndex = msg[charIndex] - 0x20; // Era "@", mudei para 0x20 para aumentar o inicio da tabela
- if (alphabetIndex < 0) alphabetIndex = 0;
- //-- Draw one character of the message --
- for (int col = 0; col < 6; col++)
- {
- for (int row = 0; row < 8; row++)
- {
- bool isOn = 0;
- if (col < 5) isOn = bitRead( alphabets[alphabetIndex][col], 7 - row ) == 1;
- Plot( numCols - 1, row, isOn);
- }
- //-- The more times you repeat this loop, the slower we would scroll --
- for (int refreshCount = 0; refreshCount < 7; refreshCount++) //change this value to vary speed
- RefreshDisplay();
- //-- Shift the bitmap one column to left --
- for (int row = 0; row < 8; row++)
- {
- for (int zone = 0; zone < numZones; zone++)
- {
- bitmap[row][zone] = bitmap[row][zone] >> 1;
- // Roll over lowest bit from the next zone as highest bit of this zone.
- if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7,
- bitRead(bitmap[row][zone + 1], 0));
- }
- }
- }
- }
- }
- //***************************** loop() **************************
- void loop()
- {
- float Celso; // Varialvel para guardar valor de temperatura
- // Varialvel em homengem ao Celso kkkkkk
- int humidade; // Varialvel para guardar valor de umidade
- String Display; // Varialvel tipo string para guardar o texto para o display
- tempSensor.measure(&temperature, &humidity, &dewpoint);
- Display = "C:"; // C: no texto
- Display += temperature; // valor da temperatura no texto
- Display += " H:"; // H: no texto
- Display += humidity; // valor da umidade no texto
- Display.toCharArray(msg, 13); // string para array
- digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
- AlphabetSoup(); // chama rotina para display
- digitalWrite(LED, LOW); // turn the LED on (LOW is the voltage level)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement