Simplified Commands
(EN google-translate)
(PL google-translate)
Im folgenden werden die verfügbaren Befehle auf der Ebene der vereinfachten Anwenderprogrammierschicht aufgelistet und beschrieben.
Die Darstellung ist geordnet nach der mittels der Befehle ansteuerbaren internen Peripherie, also danach, welche der folgenden Komponenten durch die angegebenen Befehle manipuliert werden können:
|
Darüber hinaus existieren vordefinierte zusätzliche Hilfsobjekte und Variablen, die die Programmierung der Uhr erleichtern sollen:
EDITOR
Mit der Methode editor(...) können Zeichen, Zahlen und Texte an den Darstellungsbereich
des Touchscreens angehangen werden.
Zeilenumbrüche können mit editor("\n"); realisiert werden.
Mit der Methode curser(zeile,spalte) kann die Stelle gesetzt werden, ab der
Zeichen in den Editor eingefügt werden.
editor(...) arbeitet etwas effizienter als die Funktion text(...)
Es wird ein monospace-Font verwendet.
Die Anzahl an Zeilen und Buchstaben pro Zeile ist abhängig von der mit
setFont(...) eingestellten Fontgröße.
BESCHLEUNIGUNGSWERTE
Wird die Funktion acceleration(); aufgerufen, werden die Sensorwerte des dreiachsigen
Beschleunigungssensors ausgelesen und in folgenden Variablen gespeichert:
int accX;
int accY;
int accZ;
int absaccX; //Absolutwerte der gleichen Sensorwerte...
int absaccY;
int absaccZ;
TOUCHPOSITION
Wird die Funktion touch(); aufgerufen, so wird die aktuelle Position
der Berührung des Touchscreens in folgenden Variablen gespeichert:
int mouseX=0;
int mouseY=0;
UHRZEIT
Wird die Funktion updateTime(); aufgerufen, wird die aktuelle Funkzeit geholt
und ihre Anteile sind über folgende Funktionen abrufbar:
int getHour12() //12 stündiger Wert der aktuellen Stunde
int getHour() //24 stündiger Wert der aktuellen Stunde
int getMinute()
int getSecond()
SERIELLER MONITOR
Während der Entwicklungszeit macht es Sinn, Variablen zur Laufzeit der Uhr auszulesen.
Die Variablen können dazu über eine über die USB-Verbindung zu PC emulierte Schnittstelle
an den Seriellen Monitor der Arduino IDE übertragen werden.
setupSERIAL(115200); //aktiviert die serielle Verbindung zum PC mit einer Baudrate von 115200.
"Serial" ist das Objekt, das dann Befehle zur Datenübertragung bereitstellt.
Beispiele:
if(Serial) Serial.println("WiFi connected");
if(Serial) Serial.print("ip:");
if(Serial) Serial.println(WiFi.localIP());
if(Serial) Serial.println();
Code 0-1: Zusätzliche Hilfsobjekte und Variablen.
Um leichter verstehbar zu machen, wie genau die Befehle benutzt werden können, ist an den Anfang jedes Bereichs ein kleiner Programmschnipsel gesetzt worden, der ein einfaches Anwendungsbeispiel der betreffenden Peripherie darstellt.
Vorgehen:
|
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: Beispielcode.
| 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.
Übung
|
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: Beispielcode.
| 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: Befehle zur Verwendung des Touchsensors.
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: Beispielcode.
| 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: Befehle zur Verwendung des 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: Beispielcode.
| 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: Befehle zur Verwendung der Echtzeituhr.
WiFi
|
|
|
Im Smartwatch-Programm anpassen: Name und Passwort des Hotspots!
Im PC-Programm anzupassen: Broadcast-IP-Adresse des Hotspot-Netzes!
Der Hotspot kann sinnvollerweise gleich durch dasjenige Gerät (PC, Laptop, Android Gerät) bereitgestellt werden, auf dem das Empfängerprogramm läuft.
Weitere Infos zu UDP und Internetprogrammierung: 67_Echtzeitsysteme/09_Internetprogrammierung/04_Java
Weitere Infos zur Einrichtung eines Hotspots am PC: 08_Archiv/06_Ing/01_Bauplan/04_Hotspot
Weitere Infos zur Einrichtung eines Hotspots bei Android: 05_esp32AV/01_Bauanleitung/01_Elektronik_und_Software/03_Videostream
TWATCH_PROC005_hotspot.zip -- PC/Laptop-seitiges Empfangsprogramm als Processing Sketch.
TWATCH_PROC005_hotspot_ANDROID.zip -- Empfangsprogramm als Processing Sketch für ein Android-Gerät (leicht modifiziert gegenüber PC-Version).
TWATCH_PROC023_WiFiminimal.zip -- Smartwatch-Projekt zum Testen von WiFi passend zu den oberen beiden Programmen.
TWATCH_PROC005_hotspot -- Vollständiges PC/Laptop-seitiges Empfangsprogramm. ACHTUNG: Broadcast-IP ist anzupassen.
import hypermedia.net.*;
String IP = "10.42.0.255"; //ANPASSEN! Broadcast IP des Hotspotnetzes
int PORT = 6000; //für UDP benötigt.
UDP udp;
String NACHRICHT="";
public void setup()
{
size(700,500);
udp = new UDP( this, 6000 );
udp.listen( true );
frameRate(10);
}
public void draw()
{
background(255);
fill(0);
textSize(20);
text("Empfangen:",30,30);
text(NACHRICHT,30,60);
udp.send("Test", IP, PORT ); //Dummy Nachricht an Smartwatch, um Antwort auszulösen.
}
//Callbackroutine für das Empfangen der IMU-Werte:
void receive( byte[] data, String ip, int port )
{
String x = new String( data );
if(x!=null && !x.equals("Test"))
NACHRICHT = x;
}
Code 0-6: Vollständiges PC/Laptop-seitiges Empfangsprogramm. ACHTUNG: Broadcast-IP ist anzupassen.
TWATCH_PROC005_hotspot_ANDROID -- Vollständiges Empfangsprogramm, Android-Version
import hypermedia.net.*;
String IP = "192.168.96.255";
int PORT = 6000; //für UDP benötigt.
UDP udp;
String NACHRICHT="";
public void setup()
{
fullScreen();
udp = new UDP( this, 6000 );
udp.listen( true );
frameRate(10);
orientation(LANDSCAPE);
}
public void draw()
{
background(255);
fill(0);
textSize(130);
text("Empfangen:",130,130);
text(NACHRICHT,130,260);
udp.send("Test", IP, PORT );
}
void receive( byte[] data, String ip, int port )
{
String x = new String( data );
if(x!=null && !x.equals("Test"))
NACHRICHT = x;
}
Code 0-7: Vollständiges Empfangsprogramm, Android-Version.
Haupttab aus dem Arduino Projekt TWATCH_PROC023_WiFiminimal, der Minimalversion zu WiFi für die T-WATCH
#include "twatch.h"
#include "variables.h"
#include "functions.h"
const char* hotspot = "hotspotK";
const char* password = "12345678";
int udpport = 6000;
void setup()
{
setupTWATCH();
setupWIFI(hotspot,password,udpport);
setFont(1, 255,255,255, 255,0,0);
backlight(true);
}
void loop()
{
//WiFi-Verbindung herstellen, wenn Knopf gedrückt und falls nicht vorhanden:
if(button() && !WIFIOKAY)
{
setupWIFI(hotspot,password,udpport);
}
//Beschleunigungswerte aktualisieren:
acceleration();
//Wenn WiFi-Verbindung vorhanden und
//auf Pakete warten aktiviert...
if(WIFIOKAY && udp.listen(UDPPORT))
{
//...dann Beschleunigungswerte an PC schicken, wenn dieser
//etwas gesendet hat:
udp.onPacket([](AsyncUDPPacket packet)
{
packet.printf("accX=%d accY=%d accZ=%d", accX,accY,accZ);
});
}
cursor(0,0);
//Beschleunigungswerte auf einfache Art und Weise anzeigen:
editor(accX);
editor('
');
editor(accY);
editor('
');
editor(accZ);
editor('
');
//Falls WiFi Verbindung vorhanden, eigene IP in dem
//Hotspot-Netz anzeigen:
if(!WIFIOKAY)
{
editor("no WiFi!");
//editor((unsigned long)millis());
}
else
{
tft->print(WiFi.localIP()); //...Originalmethode
//editor(WiFi.localIP()); ...klappt nicht
}
editor('
');
delay(100);
}
Code 0-8: Haupttab aus dem Arduino Projekt TWATCH_PROC023_WiFiminimal, der Minimalversion zu WiFi für die T-WATCH
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-9: Beispielcode.
| Command | Example | Description | Hints |
|---|---|---|---|
| button() : bool | if(button()){MODE++;} | React on button. | function returns true if button pressed, else false. |
Tabelle 0-5: Befehle zur Verwendung des physikalischen Knopfes (Button).
TWATCH_PROC023_WiFiminimal -- Haupttab des Smartwatch-Projektes zum Testen von WiFi
#include "twatch.h"
#include "variables.h"
#include "functions.h"
const char* hotspot = "hotspotK";
const char* password = "12345678";
int udpport = 6000;
void setup()
{
setupTWATCH();
setupWIFI(hotspot,password,udpport);
setFont(1, 255,255,255, 255,0,0);
backlight(true);
}
void loop()
{
//WiFi-Verbindung herstellen, wenn Knopf gedrückt und falls nicht vorhanden:
if(button() && !WIFIOKAY)
{
setupWIFI(hotspot,password,udpport);
}
//Beschleunigungswerte aktualisieren:
acceleration();
//Wenn WiFi-Verbindung vorhanden und
//auf Pakete warten aktiviert...
if(WIFIOKAY && udp.listen(UDPPORT))
{
//...dann Beschleunigungswerte an PC schicken, wenn dieser
//etwas gesendet hat:
udp.onPacket([](AsyncUDPPacket packet)
{
packet.printf("accX=%d accY=%d accZ=%d", accX,accY,accZ);
});
}
cursor(0,0);
//Beschleunigungswerte auf einfache Art und Weise anzeigen:
editor(accX);
editor('
');
editor(accY);
editor('
');
editor(accZ);
editor('
');
//Falls WiFi Verbindung vorhanden, eigene IP in dem
//Hotspot-Netz anzeigen:
if(!WIFIOKAY)
{
editor("no WiFi!");
//editor((unsigned long)millis());
}
else
{
tft->print(WiFi.localIP()); //...Originalmethode
//editor(WiFi.localIP()); ...klappt nicht
}
editor('
');
delay(100);
}
Code 0-10: TWATCH_PROC023_WiFiminimal -- Haupttab des Smartwatch-Projektes zum Testen von WiFi
Bild 0-1: Test des Projektes TWATCH_PROC023_WiFiminimal.
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-11: Beispielcode.
| 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: Befehle zur Verwendung des Motors.