燈板程式範例
附錄
以一般的程式語言來寫Lumex 燈板程式要如何寫?以下簡附Arduino、 C 以及Python 的程式提供參考:
Python
Python Code Download
import serial #外掛通訊功能
import time #時間功能
import random
#定義跟ezdisplay相連的UART
class Send_Rcv():
def __init__(self,comport):
self.ser = serial.Serial(comport, baudrate=115200, timeout=0.05)
def SendCommand(self,command):
self.ser.write(command.encode())
def ReadLine(self):
return self.ser.readline.decode("utf-8").strip()
def Readuntil(self,c1):
self.ser.read_until(c1.encode())
#<--end ez物件
at_cmd = Send_Rcv('/COM3') #指定跟 ezDisplay 連接的 UART port
at_cmd.SendCommand("at2b=(0)") #設定為覆蓋模式
at_cmd.Readuntil('E') #等待燈板完成工作
loop = 1
while loop > 0:
at_cmd.SendCommand("atd0=()") #清除畫面
at_cmd.Readuntil('E')
at_cmd.SendCommand("atef=(4)") #設定文字顏色為綠色
at_cmd.Readuntil('E')
at_cmd.SendCommand("at83=(1,0,Count:)") #顯示8x16字型 Count: 字串
at_cmd.Readuntil('E')
at_cmd.SendCommand("atef=(3)") #設定數字顏色為藍色
at_cmd.Readuntil('E')
for i in range(0,100,1):
at_cmd.SendCommand("at83=(1,6,%d)"%i) #顯示8x16字型字串
at_cmd.Readuntil('E')
time.sleep(0.1)
C
C Sample Code Download
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "calendar.h"
#include "usart.h"
#include "stm32f10x_gpio.h"
void Wait_for_echo(void);
void main(void)
{
int i,Temp,Light;
delay_init();
USART_Configuration();
Delay_ms(1000);
printf("atd0=()"); //清除畫面
Wait_for_echo(); //等待燈板完成動作
Delay_ms(500);
printf("at2b=(0)"); //設定為覆蓋模式
Wait_for_echo(); //等待燈板完成動作
while (1)
{
printf("atd0=()"); //清除畫面
Wait_for_echo();
printf("atef=(4)"); //設定文字的顏色
Wait_for_echo();
printf("at83=(1,0,Count:)"); //顯示8x16字型字串
Wait_for_echo();
printf("atef=(3)"); //設定數字的顏色
Wait_for_echo();
for (i=0;i<100;i++)
{
printf("at83=(1,6,%d)",i); //顯示8x16字型字串
Wait_for_echo();
Delay_ms(100);
}
}
}
void Wait_for_echo(void)
{
while (USART_GetFlagStatus(UART1, USART_FLAG_RXNE)== RESET){}
while (USART_ReceiveData(UART1)!= 'E'){}
USART_ClearFlag(UART1, USART_FLAG_RXNE);
}
Arduino
Arduino Code Download
int i;
void setup() {
Serial.begin(115200); //設定UART
delay(1000);
Serial.print("atd0=()"); //清除畫面
while (Serial.read() != 'E') {} //等待燈板完成動作
Serial.print("at2b=(0)"); //設定為覆蓋模式
while (Serial.read() != 'E') {} //傳送指令終止的字元
}
void loop() {
Serial.print("atd0=()");
while (Serial.read() != 'E') {}
Serial.print("atef=(4)"); //設定文字顏色為綠色
while (Serial.read() != 'E') {}
Serial.print("at83=(1,0,Count:)"); //顯示8x16字型 Count: 字串
while (Serial.read() != 'E') {}
Serial.print("atef=(3)"); //設定數字顏色為藍色
while (Serial.read() != 'E') {}
for (i=0;i<100;i++)
{
Serial.print("at83=(1,6,"); //傳送部分指令
Serial.print(i); //傳送指令中變動的部分
Serial.write(')'); //傳送指令終止的字元
while (Serial.read() != 'E') {}
delay(50);
}
}