I/0-Box Snackautomat Code
Aus TBZ_-_Wiki
Version vom 28. Juni 2011, 08:45 Uhr von Moritz.kuendig (Diskussion | Beiträge)
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BESCHREIBUNG: Dieses Program wird zusammen mit der 1OBox (K8055D_C) zu einem Getränkeautomate. Dafür werden die Knöpfe (1-5) und LEDs (1-5) benutzt. Mit den Knöpfen werden bestellt und die LEDs zeigen an, ob sich noch Produkte im Automat befinden! Dies wird zusätzlich mit Bilder im Program angezeigt? ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ //--------------------------------------------------------------------------- #include "getraenkeautomat.h" //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "K8055D_C.h" #pragma package(smart_init) #pragma resource "*.dfm" int i; int produkta[5]; Tfrm_automat *frm_automat; //--------------------------------------------------------------------------- __fastcall Tfrm_automat::Tfrm_automat(TComponent* Owner) : TForm(Owner) { for (i = 0; i < 5; i++) { produkta[i]=5; // Produkte nachfüllen } } //--------------------------------------------------------------------------- void __fastcall Tfrm_automat::anzahlAuffrischen() { txt_produkte1->Text=produkta[0]; // eines nach dem anderen Nachfüllen txt_produkte2->Text=produkta[1]; // eines nach dem anderen Nachfüllen txt_produkte3->Text=produkta[2]; // eines nach dem anderen Nachfüllen txt_produkte4->Text=produkta[3]; // eines nach dem anderen Nachfüllen txt_produkte5->Text=produkta[4]; // eines nach dem anderen Nachfüllen } //--------------------------------------------------------------------------- void __fastcall Tfrm_automat::Connect1Click(TObject *Sender) { int h = OpenDevice(0); if (h == 0) { txt_zustand->Text="Bereit..."; //READY Connect1->Enabled=False; // Button deakt. Timer->Enabled = true; // TIMER an } else { txt_zustand->Text="No Dewweeiiis !!"; // nichts gefunden (ausgedrückt in gutem Englisch) } } //--------------------------------------------------------------------------- void __fastcall Tfrm_automat::but_fillClick(TObject *Sender) { for (i = 0; i < 5; i++) { produkta[i]=5; // alle Auffüllen } //:P // ALLLE AN img_produkt1->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\red.png"); img_produkt2->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\red.png"); img_produkt3->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\red.png"); img_produkt4->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\red.png"); img_produkt5->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\red.png"); int jo; for (jo = 1; jo <= 5; jo++) { SetDigitalChannel(jo); // alle Auffüllen //=) } anzahlAuffrischen(); // Aktualisieren } //--------------------------------------------------------------------------- void __fastcall Tfrm_automat::TimerTimer(TObject *Sender) { // Knöpfe holen long knoepfe = ReadAllDigital(); // Alle lesen Timer->Enabled = false; // Timer aus keine überschneidungen // 1. Produkt break if ((knoepfe & 1)>0&&produkta[0]>0) { // Anzeige Sleep(200); produkta[0]=produkta[0]-1; // Produktabzug list->AddItem("BOUNTY", NULL); if (produkta[0]==0) { // Channel ab wenn LEER img_produkt1->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\black.png"); ClearDigitalChannel(1); } } anzahlAuffrischen(); // 2. Produkt if ((knoepfe & 2)>0&&produkta[1]>0) // Kontrolle ob Knopf aktiv { // Anzeige Sleep(200); produkta[1]=produkta[1]-1; // Produktabzug list->AddItem("Mars", NULL); // Channel ab wenn LEER if (produkta[1]==0) { img_produkt2->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\black.png"); ClearDigitalChannel(2); } } anzahlAuffrischen(); Timer->Enabled = true; // 3. Produkt if ((knoepfe & 4)>0&&produkta[2]>0) // Kontrolle ob Knopf aktiv { // Anzeige Sleep(200); produkta[2]=produkta[2]-1; // Produktabzug list->AddItem("Snickers", NULL); if (produkta[2]==0) // Channel ab wenn LEER { img_produkt3->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\black.png"); ClearDigitalChannel(3); } } anzahlAuffrischen(); Timer->Enabled = true; // 4. Produkt if ((knoepfe & 8)>0&&produkta[3]>0) // Kontrolle ob Knopf aktiv { // Anzeige Sleep(200); produkta[3]=produkta[3]-1; // Produktabzug list->AddItem("Haribo", NULL); // Channel ab wenn LEER if (produkta[3]==0) { img_produkt4->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\black.png"); ClearDigitalChannel(4); // Channel ab } } anzahlAuffrischen(); Timer->Enabled = true; // 5. Produkt if ((knoepfe & 16)>0&&produkta[4]>0) // Kontrolle ob Knopf aktiv { // Anzeige Sleep(200); produkta[4]=produkta[4]-1; // Produktabzug list->AddItem("MilkyWay!", NULL); if (produkta[4]==0) // Channel ab wenn LEER { img_produkt5->Picture->LoadFromFile("J:\\Siemens\\S-CH_getraenkeautomat\\Version1.1\\img\\black.png"); ClearDigitalChannel(5); // Channel ab } } anzahlAuffrischen(); Timer->Enabled = true; // wieder Aktivieren } //--------------------------------------------------------------------------- void __fastcall Tfrm_automat::but_clearClick(TObject *Sender) { list->Clear(); // liste löschen } //---------------------------------------------------------------------------