Processing 學習 7-segment 字型
參考網站
https://senzor.robotika.sk/sensorwiki/index.php/Processing_7-segment_display
note
1.
下載字型檔
Segment7Standard.otf
2.
轉成TTF檔
參考網站
http://www.freefontconverter.com/
3.
win7 新增字型
參考網站
https://blog.xuite.net/yh96301/blog/29389981-Windows+7+%E5%AE%89%E8%A3%9D%E5%AD
%97%E5%9E%8B
4.
/* Arduino 範例:
* 讀取接在 pin 0 上的可變電阻,並將讀值列印到 Serial Port
*/
int potPin = 0; // 可變電阻接在 pin 0 上
int adcValue = 0;
void setup() {
// 開啟 Serial port, 通訊速率為 9600 bps
Serial.begin(9600);
}
void loop() {
adcValue = 0; // Filter - average from 16 values
for (int i = 1; i<=4; i++)
adcValue = adcValue + analogRead(0);
adcValue = adcValue/4;
char tempString[10]; // Used for sprintf
// 讀取可變電阻
//int sensorValue = analogRead(potPin);
// 將讀值列印到 Serial Port, 以位元組(Byte)的格式寫出
// 讀值除以 4, 把 0-1023 的數值按比例縮放為 0-255 之間的數值
//Serial.write(sensorValue/4);
sprintf(tempString, "%4d",adcValue); // Convert into a string that is right
adjusted
Serial.println(tempString); // Works too, but we don't need trailing
spaces ' ' in the front
delay(100);
}
5.
import processing.serial.*;
int adcValue = 0; // value received from Serial
// String Unit="mA";
// String Unit="kΩ";
// String Unit="°C"; // We can use Unicode chars directly
String Unit="\u00B0C"; // Unicode codes may be entered as well
Serial myPort;
PFont Segment, Units;
void setup() {
// Setup the display window
size(480, 180); // Size of the window
Segment = createFont("Segment7", 150); // Assign fonts and size
Units = createFont("Arial", 40);
textFont(Segment);
textAlign(RIGHT); // Text align
fill(250,250,0); // Font color is yellow = red + green
println(Serial.list()); // List all the available serial ports
// Then open the port you're using, my is the first, i.e. '0'
myPort = new Serial(this, Serial.list()[2], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
}
void draw()
{ // Let's start to display
background(0,0,0); // set the background color black
textFont(Segment);
text(adcValue, 400, 150);
textFont(Units);
text(Unit,465,65);
}
void serialEvent(Serial myPort)
{
String inString = myPort.readStringUntil('\n'); // get the ASCII string:
if (inString != null)
{
inString = trim(inString); // trim off any whitespace
adcValue = int(inString); // convert into an integer
adcValue =int(map(adcValue, 0, 1023, 0, 1023)); // possible range
adjusting
}
}
留言列表