Components and supplies
Arduino Yun
Sure Led Matrix
Project description
Code
Code snippet #1
arduino
1/******** 2Control a sure led matrix through your browser 3 4Go on http://arduino.local/sd/message , write your 5message in the form and click the button and it 6will appear on the matrix as a scrolling text. 7 8This sketch put received messages inside a queue and display 9them in the correct order. 10New messages will overwrite old ones if the buffer is full. 11 12 13Written by Angelo Scialabba 14@12 Sept 2013 15 16********/ 17#include <font_5x4.h> 18#include <HT1632.h> 19#include <images.h> 20#include <Bridge.h> 21#include <YunServer.h> 22#include <YunClient.h> 23 24YunServer server; 25int x_pos = 0; 26int curr_msg, last_msg; 27int wd; 28String msg[10]; //10 messages can be stored in the queue 29char final_message[32]; 30 31 32void setup () { 33 // Setup and begin the matrix 34 // HT1632.begin(CS1,WR,DATA) 35 HT1632.begin( 9, 10, 11); 36 Serial.begin(9600); 37 Bridge.begin(); 38 server.listenOnLocalhost(); 39 server.begin(); 40 41 //************Set the standard message************ 42 msg[0] = "No MSG"; 43 msg[0].toCharArray(final_message,32); 44 wd = HT1632.getTextWidth(final_message, FONT_5X4_WIDTH, FONT_5X4_HEIGHT); // Give the width, in columns, of the assigned string 45 46 //************Set the buffer's variables********* 47 curr_msg = 0; 48 last_msg = 0; 49} 50 51void loop () { 52 //*********Read new message from the server************** 53 YunClient client = server.accept(); 54 55 if(client) { 56 String command = client.readStringUntil('/'); 57 if (command == "msg") { 58 if (last_msg > 8 ) last_msg = 0; 59 else last_msg++; 60 msg[last_msg] = client.readStringUntil('/'); 61 } 62 client.stop(); 63 64 } 65 66 67 //*****Display the message on the matrix***** 68 HT1632.drawTarget(BUFFER_BOARD(1)); 69 HT1632.clear(); 70 HT1632.drawText(final_message, 2*OUT_SIZE - x_pos, 2, FONT_5X4, FONT_5X4_WIDTH, FONT_5X4_HEIGHT, FONT_5X4_STEP_GLYPH); 71 HT1632.render(); 72 73 74 75 //*************Scroll the message and select new messages***************** 76 77 x_pos++;; //shift the message of 1 column to left 78 79 //check if the the entire message scrolled out the matrix 80 if (x_pos == (wd + OUT_SIZE * 2)) { 81 82 x_pos = 0; //set the message position to the initial position 83 84 if (curr_msg!=last_msg){ //is there an unread message? 85 86 if (curr_msg < 9 ) curr_msg++; //select the next message 87 else curr_msg = 0; //end of the buffer, start from beginning (the next message overwrote the first) 88 msg[curr_msg].toCharArray(final_message,32); //convert the string into a char array 89 wd = HT1632.getTextWidth(final_message, FONT_5X4_WIDTH, FONT_5X4_HEIGHT); // Give the width, in columns, of the assigned string 90 91 } 92 } 93 94 delay(150); 95}
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
Table of contents
Intro
4
0