Schreiben eines Hello world - Programms
(EN google-translate)
(PL google-translate)
Gehen Sie die nachfolgenden Schritte durch:
|
1. Vorbereitungen
|
TTGO_TWatch_Library-1.4.3.zip -- Kopie der benötigten Bibliothek.
TWATCH_PROC023.zip -- Beispielprojekt.
2. Testen eines Beispielprojektes
|
Bild 0-1: Einstellungen unter "Werkzeuge".
|
TWATCH_PROC005_hotspot.zip -- Processing-Sketch, bitte herunterladen und in /home/fhbstud/sketchbook/ entpacken (Linux).
3. Hello World Projekt
|
#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-1: Neuer Quelltext im Tab "TWATCH_Hello_World".
|
Bild 0-2: Anzeige der Uhr nach Übertragung des Hello World-Programms.
Bild 0-3: Screenshot des Projekts nach der Anpassung.
TWATCH_Hello_World.zip -- Ergänzend sei hier auch das Hello World-Projekt selbst komplett zur Verffügung gestellt.
4. Hello World Projekt OHNE Vereinfachte Anwenderprogrammierschicht
Unter direkter Verwendung der TTGO_TWatch_Library V1.4.3 könnte ein Hello World - Programm folgendermassen aussehen:
//#include "twatch.h"
//#include "variables.h"
//#include "functions.h"
#define LILYGO_WATCH_2020_V3 // To use T-Watch2020 V3, please uncomment this line
//für wav:
// Except T-Watch2020, other versions need to be selected according to the actual situation
#if !defined(LILYGO_WATCH_2020_V1) && !defined(LILYGO_WATCH_2020_V3)
// T-Watch comes with the default backplane, it uses internal DAC
#define STANDARD_BACKPLANE
// Such as MAX98357A, PCM5102 external DAC backplane
// #define EXTERNAL_DAC_BACKPLANE
#else
// T-Watch2020 uses external DAC
#undef STANDARD_BACKPLANE
#define EXTERNAL_DAC_BACKPLANE
#endif
#include <LilyGoWatch.h>
#pragma mark - Depend ESP8266Audio and ESP8266_Spiram libraries
//UDP:
#include "AsyncUDP.h"
#include <WiFi.h>
//RTC time
#include <soc/rtc.h>
#include <time.h>
//Tongenerator
#include <HTTPClient.h> //Remove Audio Lib error
#include "AudioOutputI2S.h"
#include "AudioFileSourceFunction.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"
AudioFileSourceFunction* file_wav;
AudioOutputI2S *output_wav;
AudioGeneratorWAV* wav_generator;
AsyncUDP udp;
TTGOClass *watch;
TFT_eSPI *tft;
BMA *sensor;
BackLight *hintergrundlicht; //Um es manipulieren zu können!!!
RTC_Date tnow;
float sine_wave(const float time) {
float tremolo = 110.f*sin(TWO_PI * 4.f * time);
float v = sin(TWO_PI * (440.f + tremolo) * time); // C
// v=v*v*v;
v *= fmod(time, 1.f); // change linear
v *= 0.5; // scale
return v;
}
void setup()
{
watch = TTGOClass::getWatch();
watch->begin();
// Turn on the backlight .. aber nicht nur das!!!!
watch->openBL();
tft = watch->tft;
sensor = watch->bma;
hintergrundlicht = watch->bl; //Hintergrundlicht als Objekt verfügbar machen!
// Accel parameter structure (siehe Kommentare in Originalbeispiel!)
Acfg cfg;
cfg.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
cfg.range = BMA4_ACCEL_RANGE_2G;
cfg.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
cfg.perf_mode = BMA4_CONTINUOUS_MODE;
// Configure the BMA423 accelerometer
sensor->accelConfig(cfg);
// Enable BMA423 accelerometer
sensor->enableAccel();
// Configure the BMA423 accelerometer
sensor->accelConfig(cfg);
// Enable BMA423 accelerometer
sensor->enableAccel();
// You can also turn it off
// sensor->disableAccel();
// Some display settings
//tft->setTextColor(random(0xFFFF));
tft->setTextColor(TFT_GREEN, TFT_BLACK);
//tft->drawString("BMA423 accel", 25, 50, 4);
tft->setTextFont(4);
//tft->setTextColor(TFT_WHITE, TFT_BLACK);
//Check if the RTC clock matches, if not, use compile time
watch->rtc->check();
//Synchronize time to system time
watch->rtc->syncToSystem();
// Get the current data
tnow = watch->rtc->getDateTime();
//wav Tongenerator
watch->enableAudio();
watch->enableLDO3();
file_wav = new AudioFileSourceFunction(1.);
file_wav->addAudioGenerators(sine_wave);
#if defined(STANDARD_BACKPLANE)
output_wav = new AudioOutputI2S(0, 1);
#elif defined(EXTERNAL_DAC_BACKPLANE)
output_wav = new AudioOutputI2S();
//External DAC decoding
output_wav->SetPinout(TWATCH_DAC_IIS_BCK, TWATCH_DAC_IIS_WS, TWATCH_DAC_IIS_DOUT);
#endif
wav_generator = new AudioGeneratorWAV();
wav_generator->begin(file_wav, output_wav);
//backlight(true);
hintergrundlicht->on();
}
void loop()
{
//text("Hello World!",width/4,height/4);
tft->drawString("Hello world!", 50, 50, 1);
//else if(TEXT_ALIGN==CENTER)
// tft->drawCentreString(text, x, y, FONT_NUMBER);
delay(100);
}
Code 0-2: Quelltext zu einem Hello World Projekt OHNE Vereinfachte Anwenderprogrammierschicht
TWATCH_Hello_World2.zip -- Hello World Projekt OHNE Vereinfachte Anwenderprogrammierschicht