- Registriert
- 19.11.2002
- Beiträge
- 16.503
Ich habe mich eben entschlossen das Programm für den Anhänger hier herauszugeben.
Das Programm besteht aus 15 Programmblöcken.
Der Name der Programmblöcke darf nicht verändert werden, ohne die Unterprogrammaufrufe auch umzubenennen.
Viel Spaß beim Nachbau.
1. Block
sketch_Schilder_Button_v6
2.Block
Alarm
3.Block
Blinker
4.Block
DrawSchild
5.Block
Eingabe
6.Block
Get_Spannung
7.Block
Rotes_Rechteck
9.Block
blink
10.Block
flash
11.Block
floatToString.h
12.Block
hoch
13.Block
reset
14.Block
runter
15.Block
updatestr_Buffer
Das Programm besteht aus 15 Programmblöcken.
Der Name der Programmblöcke darf nicht verändert werden, ohne die Unterprogrammaufrufe auch umzubenennen.
Viel Spaß beim Nachbau.
1. Block
sketch_Schilder_Button_v6
Code:
// Dieses Programm fragt die Menütastatur ab.
// Das Programm benötigt tinyFAT.h; UTFT.h; UTFT_tinyFAT.h; UTuch.h !!
// Einbindung der Bibliotheken
#include <tinyFAT.h>
#include <UTFT.h>
#include <UTFT_tinyFAT.h>
#include <UTouch.h>
#include "floatToString.h"
// Deklaration des benutzten Fonts
extern uint8_t BigFont[];
extern uint8_t SmallFont[];
// Festlegung der Pins für das Touchfeld
UTouch myTouch(6,5,4,3,2);
// Deklaration der Variablen
int x, y;
char stCurrent[3]=""; // ---------- Buffer anlegen unnd mit Leer-String füllen.
int stCurrentLen=0;
char stLast[3]=""; // -------------- leeren Touchscreen-Tastaturpuffer für 3 Stellen anlegen
int ledGlPf = 42; // --------------- LED Gruppe linker Pfeil
int ledGrPf = 43; // --------------- LED Gruppe rechter Pfeil
int ledGlKr = 44; // --------------- LED Gruppe links Kreuz
int ledGrKr = 45; // --------------- LED Gruppe rechts Kreuz
int ledGrFl = 46; // --------------- LED Gruppe Blitzer oben
int ledBlLi = 47; // --------------- LED Linkes Anhänger-Blinklicht
int ledBlRe = 48; // --------------- LED Rechtes Anghänger-Blinklicht
int ledRuLi = 49; // --------------- LED Rücklicht
int led = 13; // --------------- nur für Test Interne LED
int PinSpannung = A0; // ----------- für Spannungsmessung
int stophochtaste = 14; // --------- Taste für Endabschaltung Warnschild aufstellen
int stopruntertaste = 15; // -------- Taste für Endabschaltung Warnschild absenken
int senkentaste = 8; // ----------- Komandotaste zum Warnschild absenken
int motorhoch = 17; // ------------- Ausgang für Motorsteuerung Warnschild aufstellen
int motorrunter = 18; // ----------- Ausgang für Motorsteuerung Warnschild absenken
int shutdown = 19; // --------------- Ausgang für shutdown - Spannung abschalten - wechsel nach standby
int stophoch = LOW; // ------------- Flag für Endabschaltung hoch erkannt
int stoprunter = LOW; // ----------- Flag für Endabschaltung runter erkannt
int senken = LOW;
int sensorValue = 0;
float messwert=0;
int DrawS = 0;
int warten = true;
int timeB = false;
long zaehlerB = 0;
int zaehlerBL = 0;
int BL = false;
int DSL = 0;
int LEDKr = 0;
int LEDPf = 0;
int ursprung = 0;
// Deklaration des Monitors und Treibers sowie der Anschlusspins. Hier Mega an TFT3,2" mit Treiber SSD1289
UTFTtf myGLCD(SSD1289, 38, 39, 40, 41); // Dran denken! Parameter für das eigene Bildschirmmodule setzen!
//------------------------------------------------------------------------------------------------------------
void setup()
{
// Initial setup
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.fillScr(33, 75, 255);
delay(2000);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(0, 0, 255);
pinMode(ledGlPf, OUTPUT);
pinMode(ledGrPf, OUTPUT);
pinMode(ledGlKr, OUTPUT);
pinMode(ledGrKr, OUTPUT);
pinMode(ledGrFl, OUTPUT);
pinMode(ledBlLi, OUTPUT);
pinMode(ledBlRe, OUTPUT);
pinMode(ledRuLi, OUTPUT);
pinMode(led, OUTPUT); // --------- Nur für Test Interne LED
pinMode(motorhoch, OUTPUT); // -- Setup für Warntafel-Motor
pinMode(motorrunter, OUTPUT);
pinMode(shutdown, OUTPUT);
pinMode(stophochtaste, INPUT);
pinMode(stopruntertaste, INPUT);
pinMode(senkentaste, INPUT);
//
DrawS = 0;
warten = false;
timeB = false;
zaehlerB = 0;
zaehlerBL = 0;
DSL = 0;
LEDKr = 0;
LEDPf = 0;
digitalWrite(ledGlPf, LOW);
digitalWrite(ledGrPf, LOW);
digitalWrite(ledGlKr, LOW);
digitalWrite(ledGrKr, LOW);
digitalWrite(ledGrFl, LOW);
digitalWrite(ledBlLi, LOW);
digitalWrite(ledBlRe, LOW);
digitalWrite(ledRuLi, HIGH);
digitalWrite(led, LOW);
analogReference(DEFAULT);
hoch();
}
void loop()
{
DrawSchild(DrawS); //------------ Auswahlbild laden
ursprung = 1;
//get_spannung();
warten = true;
while (warten)
{
senken = digitalRead(senkentaste);
if (senken == HIGH)
{
runter();
}
get_spannung();
eingabe();
}
}
2.Block
Alarm
Code:
void alarm()
{
int alarmblinker = 1;
do
{
digitalWrite(ledBlLi, HIGH);
digitalWrite(ledBlRe, HIGH);
delay(150);
digitalWrite(ledBlLi, LOW);
digitalWrite(ledBlRe, LOW);
delay(150);
}
while(alarmblinker == 1);
}
3.Block
Blinker
Code:
void Blinker(int BlLi)
{
switch(BlLi)
{
case true:
digitalWrite(ledBlLi, HIGH);
digitalWrite(ledBlRe, HIGH);
break;
case false:
digitalWrite(ledBlLi, LOW);
digitalWrite(ledBlRe, LOW);
break;
}
}
4.Block
DrawSchild
Code:
void DrawSchild(int DS)
{
// (C)2013 Winfried Schmickler
// Dieses Programm ist eine loadBitmap()-Funktion.
// Sie läd Bilder von der SD-Karte am TFT-Shield
// Dieses Programm benötigt UTFT_tinyFAT, UTFT v1.2 oder höher,
// genauso wie die tinyFAT v3.0 oder höher.
// Die Bildfiles müssen auf der SD Karte vorhanden sein! In richtiger Reihenfolge !! Menu muss PIC001.RAW heißen!
// Im Kartenschart muss eine FAT16 Formatierte SD-Karte sein.
// Deklaration der benutzten Schriftgröße
extern uint8_t BigFont[];
// Deklaration des Monitors und Treibers sowie der Anschlusspins. Hier Mega an TFT3,2" mit Treiber SSD1289
UTFTtf myGLCD(SSD1289, 38, 39, 40, 41); // Dran denken! Parameter für das eigene Bildschirmmodule setzen!
// Liste der Filenamen zum Anzeigen.
char* files320[]={
"PIC000.RAW","PIC001.RAW","PIC002.RAW","PIC003.RAW","PIC004.RAW","PIC005.RAW","PIC006.RAW","PIC007.RAW","PIC008.RAW","PIC009.RAW","PIC010.RAW","PIC011.RAW","PIC012.RAW" }; // 320x240
char* files[13]; //Menge der Bildfiles
int picsize_x, picsize_y;
boolean display_rendertime=false; // Auf true setzen, wenn die Renderzeit nach dem laden des Bildes angezeigt werden soll.
boolean display_filename=false; // Auf false setzen wenn keine Filenamen angezeigt werden sollen
word res;
long sm, em;
myGLCD.InitLCD();
myGLCD.clrScr();
file.initFAT();
myGLCD.setColor(255,255,255);
myGLCD.setFont(BigFont);
picsize_x=myGLCD.getDisplayXSize();
picsize_y=myGLCD.getDisplayYSize();
switch (picsize_x)
{
case 320:
for (int z=0; z<sizeof(files320)/sizeof(*files320);z++)
files[z] = files320[z];
break;
}
int i= DS;
if (files[i]!="")
{
sm=millis();
res=myGLCD.loadBitmap(0, 0, picsize_x, picsize_y, files[i]);
em=millis();
if (res!=0)
{
if (res==0x10)
{
myGLCD.fillScr(33, 75, 255);
myGLCD.setBackColor(33, 75, 255);
myGLCD.print("File not found...", 10, 30);
myGLCD.print(files[i], 10, 50);
// myGLCD.print("Please touch Screen.", 10, 70);
// myGLCD.print("Wait of clear Screen", 10, 90);
// myGLCD.print("before touch.", 10, 110);
}
else
{
myGLCD.print("ERROR: ", 0, 0);
myGLCD.printNumI(res, 56, 0);
}
delay(5000);
software_Reset();
}
else
{
if (display_rendertime==true)
{
myGLCD.print("Rendertime (secs):", 0, 0);
myGLCD.printNumF(float((em-sm)/1000.0), 2, 160,0);
}
if (display_filename==true)
{
myGLCD.print(files[i], CENTER, myGLCD.getDisplayYSize()-12);
}
}
}
if (DS > 0)
{
SchildDelete(DS);
}
}
5.Block
Eingabe
Code:
void eingabe()
{
// --------------------------------------------------- Tasteneingabe auswerten
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
//---------------------------------------------------- Auswertung der Tasten
if ((y>=10) && (y<=60)) // 1. Zeile
{
if ((x>=10) && (x<=75)) // Button: 1
{
waitForIt(10, 10, 75, 60);
DrawS = 1;
updateStr('1');
}
if ((x>=85) && (x<=155)) // Button: 2
{
waitForIt(85, 10, 155, 60);
DrawS = 2;
updateStr('2');
}
if ((x>=165) && (x<=230)) // Button: 3
{
waitForIt(165, 10, 230, 60);
DrawS = 3;
updateStr('3');
}
if ((x>=243) && (x<=308)) // Button: 4
{
waitForIt(243, 10, 308, 60);
DrawS = 4;
updateStr('4');
}
}
//-------------------------------------------------------
if ((y>=70) && (y<=120)) // 2.Zeile
{
if ((x>=10) && (x<=75)) // Button: 5
{
waitForIt(10, 70, 75, 120);
DrawS = 5;
updateStr('5');
}
if ((x>=85) && (x<=155)) // Button: 6
{
waitForIt(85, 70, 155, 120);
DrawS = 6;
updateStr('6');
}
if ((x>=165) && (x<=230)) // Button: 7
{
waitForIt(165, 70, 230, 120);
DrawS = 7;
updateStr('7');
}
if ((x>=243) && (x<=308)) // Button: 8
{
waitForIt(243, 70, 308, 120);
DrawS = 8;
updateStr('8');
}
}
//--------------------------------------------------------
if ((y>=130) && (y<=180)) // 3.Zeile
{
if ((x>=10) && (x<=75)) // Button: 9
{
waitForIt(10, 130, 75, 180);
DrawS = 9;
updateStr('9');
}
if ((x>=85) && (x<=155)) // Button: 10
{
waitForIt(85, 130, 155, 180);
DrawS = 10;
updateStr('10');
}
if ((x>=165) && (x<=230)) // Button: 11
{
waitForIt(165, 130, 230, 180);
DrawS = 11;
updateStr('11');
}
if ((x>=243) && (x<=308)) // Button: 12
{
waitForIt(243, 130, 308, 180);
DrawS = 12;
runter(); // --- Taste 12 kein AUS Befehlt "runter()" entfernen
updateStr('12');
}
}
//----------------------------------------------------
if ((y>=195) && (y<=230)) // 4,Zeile
{
if ((x>=7) && (x<=150)) // ------------------------ Button: Clear
{
waitForIt(7, 195, 150, 230);
stCurrent[0]='\0';
stCurrentLen=0;
myGLCD.setColor(182, 182, 182);
myGLCD.fillRect(240, 130, 311, 183);
}
if ((x>=170) && (x<=307)) // ---------------------- Button: Enter
{
waitForIt(170, 195, 307, 230);
if (stCurrentLen>0)
{
for (x=0; x<stCurrentLen+1; x++)
{
stLast[x]=stCurrent[x];
}
stCurrent[0]='\0'; // ------------------------ Buffer leeren
stCurrentLen=0;
DrawSchild(DrawS);
}
else // ----------------------------------------- Fehlerbehandlung
{
for(int w; w<4; w++)
{
DrawS = 0;
myGLCD.setColor(255, 0, 0);
myGLCD.print("BUFFER EMPTY", CENTER, 120);
delay(500);
myGLCD.print(" ", CENTER, 120);
delay(500);
myGLCD.setColor(0, 255, 0);
}
warten = false;
}
}
}
}
}
6.Block
Get_Spannung
Code:
void get_spannung()
{
// ------------ SPANNUNGSMESSUNG ----------
sensorValue = analogRead(PinSpannung); // --------------------- hole Wert
messwert=(float)24/1023*sensorValue; // ----------------------- Wert umwandeln für Anzeige 0..24.0 Volt
myGLCD.setColor(255, 255, 255);
if(DrawS == 0)
{
myGLCD.setBackColor(182, 182, 182);
myGLCD.print(floatToString(buffer,messwert,2), 244, 150);
}
else
{
myGLCD.setFont(SmallFont);
myGLCD.setBackColor(136, 136, 136);
// myGLCD.print(floatToString(buffer,messwert,2), 5, 220); // - für BigFont
// myGLCD.print("V", 72, 220); // ----------------------------- für BigFont
myGLCD.print(floatToString(buffer,messwert,2), 5, 225); // --- für SmallFont
myGLCD.print("Volt", 40, 225); // ---------------------------- für SmallFont
myGLCD.setBackColor(0, 0, 255);
myGLCD.setFont(BigFont);
}
if (messwert <= 7.2 && ursprung == 1) // ---------- Wenn Akkuspannung kleiner als 7,2 Volt shutdown einleiten
{
runter();
}
}
7.Block
Rotes_Rechteck
Code:
//
// Zeichne roten Rahmen während dem Tastendruck
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(150, 150, 150); // zeichne grauen Rahmen nach dem Tastendruck
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
[CODE]
[HR][/HR]
8.Block
SchildDelete
[CODE]void SchildDelete(int DSL)
{
warten = true;
while (warten)
{
senken = digitalRead(senkentaste);
if (senken == HIGH)
{
runter();
}
if (myTouch.dataAvailable()) // --------------------- Abfragen des Touchfeldes
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=10) && (y<=230)) // --------------------- fast ganzer Monitor
{
if ((x>=10) && (x<=310)) // --------------------- Button: Schild löschen
{
software_Reset(); // -------------------- Neustart für neue Schildauswahl
}
}
}
if(zaehlerB == 0)
{
flash();
Blinker(false);
if((DSL == 6) || (DSL == 7) || (DSL == 10) || (DSL == 11))
{
timeB = true;
blink(timeB);
}
}
zaehlerB = zaehlerB +1;
if(zaehlerB == 17500)
{
Blinker(true);
}
if(zaehlerB == 35000)
{
flash();
Blinker(false);
timeB = false;
blink(timeB);
}
if(zaehlerB == 52500)
{
Blinker(true);
}
if(zaehlerB == 70000)
{
zaehlerB = 0;
}
}
}
9.Block
blink
Code:
void blink(int on)
{
switch (DrawS) // Auswahl des Blinkmodus nach Schildnummer
{
case 6:
LEDKr = ledGlKr; // LED Gruppe links Kreuz
LEDPf = ledGrKr; // LED Gruppe rechts Kreuz
break;
case 7:
LEDKr = ledGlKr;
LEDPf = ledGrKr;
break;
case 10:
LEDKr = ledGlKr;
LEDPf = ledGlPf; // LED Gruppe links Pfeil
break;
case 11:
LEDKr = ledGrKr;
LEDPf = ledGrPf; // LED Gruppe rechts Pfeil
break;
}
switch(on) // Ein- oder Ausschalten der Warnlampen
{
case true:
digitalWrite(LEDKr, HIGH); // schaltet die LED ein (HIGH voltage level)
digitalWrite(LEDPf, HIGH);
delay(100); // warten für milli-sekunden
digitalWrite(LEDKr, LOW); // schaltet die LED aus (LOW voltage level)
digitalWrite(LEDPf, LOW);
delay(100); // warten für milli-sekunden
digitalWrite(LEDKr, HIGH); // schaltet die LED ein (HIGH voltage level)
digitalWrite(LEDPf, HIGH);
delay(100); // warten für milli-sekunden
digitalWrite(LEDKr, LOW); // schaltet die LED aus (LOW voltage level)
digitalWrite(LEDPf, LOW);
delay(100); // warten für milli-sekunden
digitalWrite(LEDKr, HIGH); // schaltet die LED ein (HIGH voltage level)
digitalWrite(LEDPf, HIGH);
break;
case false:
digitalWrite(LEDKr, LOW); // schaltet die LED aus (LOW voltage level)
digitalWrite(LEDPf, LOW);
break;
}
}
10.Block
flash
Code:
void flash()
{
digitalWrite(ledGrFl, HIGH);
delay(100); // wait for 100 milli-second
digitalWrite(ledGrFl, LOW);
delay(100);
digitalWrite(ledGrFl, HIGH);
delay(100); // wait 100 for milli-second
digitalWrite(ledGrFl, LOW);
get_spannung();
}
11.Block
floatToString.h
Code:
#include <stdio.h>
#include <stdlib.h>
// floatToString.h
//
// float to string
//
char buffer[25];
// If you don't save this as a .h, you will want to remove the default arguments
// uncomment this first line, and swap it for the next. I don't think keyword arguments compile in .pde files
//char * floatToString(char * outstr, float value, int places, int minwidth=, bool rightjustify) {
char * floatToString(char * outstr, float value, int places, int minwidth=0, bool rightjustify=false) {
// this is used to write a float value to string, outstr. oustr is also the return value.
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;
int c = 0;
int charcount = 1;
int extra = 0;
// make sure we round properly. this could use pow from <math.h>, but doesn't seem worth the import
// if this rounding step isn't here, the value 54.321 prints as 54.3209
// calculate rounding term d: 0.5/pow(10,places)
float d = 0.5;
if (value < 0)
d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
d/= 10.0;
// this small addition, combined with truncation will round our values properly
tempfloat += d;
// first get value tens to be the large power of ten less than value
if (value < 0)
tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
tens *= 10.0;
tenscount += 1;
}
if (tenscount > 0)
charcount += tenscount;
else
charcount += 1;
if (value < 0)
charcount += 1;
charcount += 1 + places;
minwidth += 1; // both count the null final character
if (minwidth > charcount){
extra = minwidth - charcount;
charcount = minwidth;
}
if (extra > 0 and rightjustify) {
for (int i = 0; i< extra; i++) {
outstr[c++] = ' ';
}
}
// write out the negative if needed
if (value < 0)
outstr[c++] = '-';
if (tenscount == 0)
outstr[c++] = '0';
for (i=0; i< tenscount; i++) {
digit = (int) (tempfloat/tens);
itoa(digit, &outstr[c++], 10);
tempfloat = tempfloat - ((float)digit * tens);
tens /= 10.0;
}
// if no places after decimal, stop now and return
// otherwise, write the point and continue on
if (places > 0)
outstr[c++] = '.';
// now write out each decimal place by shifting digits one by one into the ones place and writing the truncated value
for (i = 0; i < places; i++) {
tempfloat *= 10.0;
digit = (int) tempfloat;
itoa(digit, &outstr[c++], 10);
// once written, subtract off that digit
tempfloat = tempfloat - (float) digit;
}
if (extra > 0 and not rightjustify) {
for (int i = 0; i< extra; i++) {
outstr[c++] = ' ';
}
}
outstr[c++] = '\0';
return outstr;
}
12.Block
hoch
Code:
void hoch()
{
get_spannung();
if (messwert >= 7.25) // ---------- Wenn Akkuspannung größer als 7,25 Volt Warntafel aufrichten
{
//digitalWrite(led, HIGH);
delay(500);
while(stophoch == LOW)
{
digitalWrite(motorhoch, HIGH);
stophoch = digitalRead(stophochtaste);
}
digitalWrite(motorhoch, LOW);
//digitalWrite(led,LOW);
stophoch = LOW;
}
else
{
alarm();
}
}
13.Block
reset
Code:
void software_Reset()
{
asm volatile (" jmp 0");
}
14.Block
runter
Code:
void runter()
{
delay(1000);
while(stoprunter == LOW)
{
digitalWrite(motorrunter, HIGH);
stoprunter = digitalRead(stopruntertaste);
}
digitalWrite(motorrunter, LOW);
stoprunter = LOW;
delay(2000);
digitalWrite(shutdown,HIGH);
}
15.Block
updatestr_Buffer
Code:
//
// Buffer für Tasteneingabe
void updateStr(int val) // --------------------- Werte in Buffer schreiben.
{
if (stCurrentLen<2) //---------------------- Buffer Stellenanzahl
{
stCurrent[stCurrentLen]=val;
stCurrent[stCurrentLen+1]='\0';
stCurrentLen++;
myGLCD.setColor(0, 255, 0);
//myGLCD.print(stCurrent, 265, 150);
myGLCD.setBackColor(182, 182, 182);
myGLCD.print(" ", 244, 150);
myGLCD.printNumI(DrawS, 265, 150);
myGLCD.setBackColor(0, 0, 255);
}
else
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
delay(500);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
myGLCD.setColor(0, 255, 0);
stCurrent[0]='\0'; // --------------------- Buffer löschen
stCurrentLen=0;
DrawSchild(0); // --------------------- Tasten neu schreiben
}
}