Simplified Commands
(EN google-translate)
(PL google-translate)
The following section lists and describes the commands available at the simplified user programming layer level.
The description is organized according to the internal peripherals that can be controlled using commands, i.e., according to which of the following components can be manipulated using the specified commands:
|
In addition, there are predefined additional helper objects and variables designed to simplify clock programming:
EDITOR The editor(...) method can be used to append characters, numbers, and text to the display area of the touchscreen. Line breaks can be implemented with editor("\n");. The curser(line,column) method can be used to set the position from which characters are inserted into the editor. editor(...) works slightly more efficiently than the text(...) function. A monospace font is used. The number of lines and characters per line depends on the font size set with setFont(...). ACCELERATION VALUES When the acceleration() function is called, the sensor values of the three-axis acceleration sensor are read out and stored in the following variables: int accX; int accY; int accZ; int absaccX; //Absolute values of the same sensor values... int absaccY; int absaccZ; TOUCHPOSITION When the touch() function is called, the current position of the touch on the touchscreen is stored in the following variables: int mouseX=0; int mouseY=0; TIME When the updateTime() function is called, the current radio time is retrieved and its components can be accessed using the following functions: int getHour12() //12-hour value for the current hour int getHour() //24-hour value for the current hour int getMinute() int getSecond() SERIAL MONITOR During the development phase, it makes sense to read variables at the clock's runtime. The variables can be transferred to the serial monitor of the Arduino IDE via an interface emulated via the USB connection to the PC. setupSERIAL(115200); //activates the serial connection to the PC with a baud rate of 115200. "Serial" is the object that then provides commands for data transmission. Examples: if(Serial) Serial.println("WiFi connected"); if(Serial) Serial.print("ip:"); if(Serial) Serial.println(WiFi.localIP()); if(Serial) Serial.println();
Code 0-1: Additional auxiliary objects and variables.
To make it easier to understand how exactly the commands can be used, a small program snippet has been placed at the beginning of each section, which shows a simple example of how the relevant peripheral can be used.
Procedure:
|
Display
|
#include "twatch.h" #include "variables.h" #include "functions.h" void setup() { setupTWATCH(); setFont(1, 255,255,255, 255,0,0); backlight(true); } void loop() { text("Hello World!",width/4,height/4); delay(100); }
Code 0-2: Sample code.
Command | Example | Description | Hints |
---|---|---|---|
setFont(FONT_NUMBER, RED,GREEN,BLUE, RED_B,GREEN_B,BLUE_B); | setFont(1, 255,255,255, 255,0,0); | Set used font. | Size, Text Color, Background Color, RGB: 0..255 |
text("String",POS_X,POS_Y); | text("Hello World!",width/4,height/4); | Shows text | text, position |
backlight(BOOL) | backlight(true); | Turn background light on or off | bool value: true or false |
stroke(RED,GREEN,BLUE) | stroke(0,0,255); | sets pen color | drawing command |
fill(RED,GREEN,BLUE) | fill(0,0,255); | sets fill color | drawing command |
noStroke() | noStroke(); | no outline | drawing command |
noFill() | noFill(); | no fill color | drawing command |
rect(x,y,width,height) | rect(30,40,70,20); | draws a rectangle | drawing command x,y left upper corner |
circle(x,y,radius) | circle(50,50,20); | draws a circle | drawing command x,y center coordinate |
line(x1,y1,x2,y2) | line(10,20,120,100); | draws a line | drawing command x1,y1 starting point, x2,y2 end point |
triangle(x1,y1,x2,y2,x3,x4) | triangle(10,10,40,10,25,25); | draws a triangle | drawing command |
Tabelle 0-1: Befehle zur Manipulation des Displays.
Exercise
|
Touch
#include "twatch.h" #include "variables.h" #include "functions.h" void setup() { setupTWATCH(); backlight(true); } void loop() { if(touch()) // updates mouseX and mouseY { //red background if screen touched background(255,0,0); } else { //else green background(0,255,0); } fill(0,0,255); //shows a circle at last touch-position, which always is saved in mouseX and mouseY. circle(mouseX,mouseY,20); delay(100); }
Code 0-3: Sample code.
Command | Example | Description | Hints |
---|---|---|---|
touch() : bool | if(touch()){MODE++;} | React on touch. | function returns true if screen touched, else false. updates mouseX and mouseY. |
Tabelle 0-2: Commands for using the touch sensor.
IMU (Inertia Measurement Unit)
#include "twatch.h" #include "variables.h" #include "functions.h" void setup() { setupTWATCH(); setFont(1, 255,255,255, 255,0,0); backlight(true); } void loop() { bool res = acceleration(); cursor(0,0); if(accX>=0) editor('+'); else editor('-'); if(absaccX<1000) editor('0'); if(absaccX<100) editor('0'); if(absaccX<10) editor('0'); editor(absaccX); editor('\n'); if(accY>=0) editor('+'); else editor('-'); if(absaccY<1000) editor('0'); if(absaccY<100) editor('0'); if(absaccY<10) editor('0'); editor(absaccY); editor('\n'); if(accZ>=0) editor('+'); else editor('-'); if(absaccZ<1000) editor('0'); if(absaccZ<100) editor('0'); if(absaccZ<10) editor('0'); editor(absaccZ); editor('\n'); delay(100); }
Code 0-4: Sample code.
Command | Example | Description | Hints |
---|---|---|---|
acceleration() | acceleration(); | Updates variables accX, accY, accZ, accabsX, accabsY, accabsZ. | sensor values from IMU are saved in predefined variables. |
Tabelle 0-3: Commands for using the IMU (Inertia Measurement Unit).
RTC (Real Time Clock)
#include "twatch.h" #include "variables.h" #include "functions.h" void setup() { setupTWATCH(); setFont(1, 255,255,255, 255,0,0); updateTime(); //RTC Zeit holen backlight(true); } void loop() { if(button()) updateTime(); //RTC Zeit holen cursor(0,0); if(getHour()<10) editor('0'); editor(getHour()); editor('\n'); if(getMinute()<10) editor('0'); editor(getMinute()); editor('\n'); if(getSecond()<10) editor('0'); editor(getSecond()); editor('\n'); delay(100); }
Code 0-5: Sample code.
Command | Example | Description | Hints |
---|---|---|---|
updateTime() | updateTime(); | gets realtime. | sets the watch to actual time zone. |
getHour() : int | int h = getHour(); | gets hours. | gets hours of actual time. |
getMinute() : int | int m = getMinute(); | gets minutes. | gets minutes of actual time. |
getSecond() : int | int m = getSecond(); | gets seconds. | gets seconds of actual time. |
Tabelle 0-4: Commands for using the real-time clock.
WiFi
Bluetooth
Button
#include "twatch.h" #include "variables.h" #include "functions.h" void setup() { setupTWATCH(); backlight(true); } void loop() { if(button()) { //red background if button pressed background(255,0,0); } else { //else green background(0,255,0); } delay(100); }
Code 0-6: Sample code.
Command | Example | Description | Hints |
---|---|---|---|
button() : bool | if(button()){MODE++;} | React on button. | function returns true if button pressed, else false. |
Tabelle 0-5: Commands for using the physical button.
Vibration
#include "twatch.h" #include "variables.h" #include "functions.h" void setup() { setupTWATCH(); setupMotor(); backlight(true); } void loop() { if(button()) { //Motor running if button pressed. motor(); } delay(100); }
Code 0-7: Sample code.
Command | Example | Description | Hints |
---|---|---|---|
setupMotor() | setupMotor(); | Make vibration possible. | function initializes motor, used in setup() |
motor() | motor(); | Runs motor for a short while. | used in loop() |
Tabelle 0-6: Commands for using the motor.