kramann.info
© Guido Kramann

Login: Passwort:










kramann.info
© Guido Kramann

Login: Passwort:




(EN google-translate)

(PL google-translate)

1. New small examples for using the screen, touchscreen, button, IMU sensor, and real-time clock

1.1 Using the function editor(...)
#include "twatch.h"
#include "variables.h"
#include "functions.h"

void setup() 
{
    setupTWATCH();
    setFont(1, 255,255,255,  0,0,0);
    backlight(true); 
}

void loop() 
{
    cursor(0,0);     
    editor("Hello\n");
    editor("Editor\n");
    editor("01234567890123456\n");
    editor("17 Spalten\n");
    editor("9 Zeilen\n");
    editor("Zeile 6\n");
    editor("Zeile 7\n");
    editor("Zeile 8\n");
    editor("Zeile 9\n");
    delay(100);      
}

Code 0-1: 1.1 Using the function editor(...)


TWATCH_PROC023_B001.zip -- 1.1 Using the function editor(...)

View of the clock -- 1.1 Using the function editor(...)

Bild 0-1: View of the clock -- 1.1 Using the function editor(...)


1.2 Using the function button()
#include "twatch.h"
#include "variables.h"
#include "functions.h"

bool zeigeText = false;

void setup() 
{
    setupTWATCH();
    setFont(1, 255,255,255,  0,0,0);
    backlight(true); 
}

void loop() 
{
  
    if(button())
    {
         zeigeText=!zeigeText;
    }
    
    if(zeigeText)
    {
        cursor(50,100);     
        editor("Hello");
    }
    else
    {
        background(0,255,0);
    }
    
    delay(100);      
}

Code 0-2: 3.2 Using the function button()


TWATCH_PROC023_B002.zip -- 1.2 Using the function button()

1.2 Using the function button() ... after pressing the button once.

Bild 0-2: 1.2 Using the function button() ... after pressing the button once.


1.3 Using the Radio-Controlled Clock
#include "twatch.h"
#include "variables.h"
#include "functions.h"

bool zeigeText = false;

void setup() 
{
    setupTWATCH();
    setFont(1, 255,255,255,  0,0,0);
    updateTime(); //RTC Zeit holen    
    backlight(true); 
}

void loop() 
{
    int h = getHour();
    int m = getMinute();
    int s = getSecond();
    cursor(0,0);
    if(h<10)
    {
        editor('0');
    }
    editor(h);
    editor(':');
    if(m<10)
    {
        editor('0');
    }
    editor(m);
    editor(':');
    if(s<10)
    {
        editor('0');
    }
    editor(s);

    fill(255,0,0);
    noStroke();
    rect(0,120,s*4,120);
    fill(0,0,0);
    rect(s*4,120,239-s*4,120);    
    delay(100);      
}

Code 0-3: 1.3 Using the Radio-Controlled Clock


TWATCH_PROC023_B003.zip -- 1.3 Using the Radio-Controlled Clock

1.3 Using the Radio-Controlled Clock

Bild 0-3: 1.3 Using the Radio-Controlled Clock


1.4 Using the Accelerometer and Vibration Motor
#include "twatch.h"
#include "variables.h"
#include "functions.h"

void setup() 
{
    setupTWATCH();
    setupMotor();
    setFont(1, 255,255,255,  0,0,0);
    backlight(true); 
}

void loop() 
{
    acceleration();
    cursor(0,0);
    editor(absaccX);    
    editor('\n');
    editor(absaccY);    
    editor('\n');
    if(absaccZ<1000) editor('0');
    if(absaccZ<100) editor('0');
    if(absaccZ<10) editor('0');
    editor(absaccZ);    

    stroke(0,0,255);
    if(absaccZ<300)
    {
        motor();
        fill(255,0,0);
    }
    else
    {
        fill(0,255,0);        
    }
    circle(120,120,50);
    delay(100);      
}

Code 0-4: 3.4 Using the Accelerometer and Vibration Motor

TWATCH_PROC023_B004.zip -- 1.4 Using the Accelerometer and Vibration Motor

1.4 Verwendung des Beschleunigungssensors und des Vibrationsmotors während Alarm.

Bild 0-4: 1.4 Verwendung des Beschleunigungssensors und des Vibrationsmotors während Alarm.


Small projects for an application program using the internal peripherals covered so far

Exercise 1

  • Write a program that activates the vibration motor for one second at the start of every full minute.

Exercise 2

  • In 1.4, the display of absaccX and absaccY is not perfect:
  • If small numbers appear first, followed by large ones, the old digits remain on the display.
  • Fix this by following the example of how absaccZ is displayed.
  • The variables accX, accY, and accZ return the acceleration values with signs, rather than just the absolute values.
  • Analyze how the signed display is implemented here in "Code 4-4: Sample Code" under "IMU (Inertial Measurement Unit)":
06_TWATCH/04_Simplified_Commands -- siehe Code 4-4.

Exercise 3


  • The millis() function returns the number of milliseconds that have elapsed since the timer was started.
  • Based on this, try to program a timer that triggers an alarm 10 seconds after the button is pressed.
  • The alarm should be acknowledged and turned off by pressing the button again.
  • The alarm should be triggered both by displaying an appropriate graphic and by activating the vibration.

Note: Call millis() with a type cast to integer, for example: int t = (int)millis();



Exercise 4

  • Come up with your own small application for the smartwatch.
  • Think of at least two fault-tolerance patterns that could be used in your project.
  • Implement your idea as far as possible.