Created
December 14, 2014 11:10
-
-
Save anonymous/5bcc21120a1fc6b63ba4 to your computer and use it in GitHub Desktop.
Processing script ticker for BlinkyMatrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Learning Processing | |
// Daniel Shiffman | |
// http://www.learningprocessing.com | |
// Exercise 17-6: Stock Ticker | |
// A class to describe a stock quote | |
class Stock { | |
String name; // Name | |
int val; // Value | |
float x; // x position | |
String display; // What we see onscreen | |
Stock(String n) { | |
name = n; | |
//val = v; | |
// Concatenate the name, value and some spaces | |
display = name + " "; | |
} | |
// A function to set x position | |
void setX(float x_) { | |
x = x_; | |
} | |
// Scroll the quote and reset it when it gets far enough offscreen | |
void move() { | |
x = x - 1; | |
if (x < width-totalW) { | |
x = width; | |
} | |
} | |
// Display the quote | |
void display() { | |
textFont(f); | |
textAlign(LEFT); | |
//fill(255); | |
text(display,x,5); | |
} | |
// Return the width of the quote | |
float textW() { | |
textFont(f); | |
return textWidth(display); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Main ticker code from // Learning Processing // Daniel Shiffman // http://www.learningprocessing.com // Exercise 17-6: Stock Ticker | |
// Other code from BlinkyTape Webpage | |
import processing.serial.*; | |
Stock[] stocks = new Stock[7]; | |
float totalW = 0; | |
PFont f; // Global font variable | |
Serial s; | |
void setup() { | |
// Connect to the first serial port we can find | |
// We assume there is a BlinkyTape there | |
for(String p : Serial.list()) { | |
// NOTE: you'll need to change the next line to match the serial port system, i.e. COMx on Windows | |
if (p.startsWith("COM5")) { | |
s = new Serial(this, p, 115200); | |
} | |
} | |
frameRate(4); // no rush here right | |
size(12,5); | |
//f = loadFont( "M37_FEEL_THE_BIT-5.vlw"); | |
//f = loadFont( "bit-01:cube_16_remix-5.vlw"); | |
f = loadFont( "5x5-Pixel-8.vlw"); | |
// Giving the stocks names and values to display | |
stocks[0] = new Stock(" MARRY"); | |
stocks[1] = new Stock("XMAS"); | |
stocks[2] = new Stock("AND "); | |
stocks[3] = new Stock("A"); | |
stocks[4] = new Stock("HAPPY"); | |
stocks[5] = new Stock("NEW"); | |
stocks[6] = new Stock("YEAR "); | |
// We space the stock quotes out according to textWidth() | |
float x = 0; | |
for (int i = 0; i < stocks.length; i++) { | |
stocks[i].setX(x); | |
x = x + (stocks[i].textW()); | |
} | |
totalW = x; | |
} | |
void draw() { | |
//image(img,0,0); | |
background(255,0,0); | |
fill(0,255,0); | |
// Move and display all quotes | |
for (int i = 0; i < stocks.length; i++) { | |
stocks[i].move(); | |
stocks[i].display(); | |
} | |
loadPixels(); | |
for (int i = 0; i < pixels.length; i++) { | |
// look at the pixel and send to the led in r,g,b | |
s.write((byte)min(254, red(pixels[i]))); | |
s.write((byte)min(254, green(pixels[i]))); | |
s.write((byte)min(254, blue(pixels[i]))); | |
println(i); | |
} | |
updatePixels(); | |
s.write((byte)255); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment