Guten Morgen und Frohe Weihnachten an alle!
Ich habe auf meinem Arduino Uno ein Programm am laufen. Dieses Programm ermöglicht mir das Zähler von Runden sowie das messen der jeweiligen Rundenzeiten von zwei spieler. Das ganze kann ich mir dann auf dem Serial Monitor anzeigen lassen.
Nun möchte ich das ganze etwas anschulicher gestalten und möchte die sachen über den serialen port auslesen.
Das klappt auch.
Nun zu meinem Problem, ich habe ich einem Fenster zwei textboxen, die linke ist für spieler 1 und die rechte für spieler zwei.
Zurzeit werden alle eregnise an die linke textbox für spieler eins geleitet.
Ich möchte es jedoch so haben, das alles was für spieler eins ausgelsen wird in die linke und das für spieler zwei in die rechte textbox ausgelsen wird.
Ich hab bereits versucht das ganze mit verschiedenen baudrate zu machen.
Spieler 1: Baudrate 4800
Spieler 2: Baudrate 9600
sodass ich es mir über verschiedene baudrates in die jeweiligen textboxen auslesen kann, dieses schaffe ich jedoch nicht und weiss nicht wie ich es anstellen soll, evtl. gibts auch bessere lösungen.
Ich habe bereits den ganzen letzten abend damit verbracht foren und andere beiträge durchzublättern sodass ich leider nicht zum ergebnis kommen konnte.
Auch bin ich ein freund der suchmaschinen und werden auch immer fündig sodass ich nur sehr selten neue themen beginne.
dies wollte ich nur vorweg nehmen damit niemand sofort fragt :"Suchfunktion benutzt ?"
Ich wäre über tipps, codes.... sehr dankbar.
Das ganze soll später über das VB programm anschasulich dargestellt werden und die Rundenzeiten etc. meine carrera anzeigen.
Ein Frohes Fest.
Gruß STefan
Hier mein Arduino Programm:
Spoiler anzeigen
Hier das VB Programm:
Spoiler anzeigen
*Posting ausgelagert*
Ich habe auf meinem Arduino Uno ein Programm am laufen. Dieses Programm ermöglicht mir das Zähler von Runden sowie das messen der jeweiligen Rundenzeiten von zwei spieler. Das ganze kann ich mir dann auf dem Serial Monitor anzeigen lassen.
Nun möchte ich das ganze etwas anschulicher gestalten und möchte die sachen über den serialen port auslesen.
Das klappt auch.
Nun zu meinem Problem, ich habe ich einem Fenster zwei textboxen, die linke ist für spieler 1 und die rechte für spieler zwei.
Zurzeit werden alle eregnise an die linke textbox für spieler eins geleitet.
Ich möchte es jedoch so haben, das alles was für spieler eins ausgelsen wird in die linke und das für spieler zwei in die rechte textbox ausgelsen wird.
Ich hab bereits versucht das ganze mit verschiedenen baudrate zu machen.
Spieler 1: Baudrate 4800
Spieler 2: Baudrate 9600
sodass ich es mir über verschiedene baudrates in die jeweiligen textboxen auslesen kann, dieses schaffe ich jedoch nicht und weiss nicht wie ich es anstellen soll, evtl. gibts auch bessere lösungen.
Ich habe bereits den ganzen letzten abend damit verbracht foren und andere beiträge durchzublättern sodass ich leider nicht zum ergebnis kommen konnte.
Auch bin ich ein freund der suchmaschinen und werden auch immer fündig sodass ich nur sehr selten neue themen beginne.
dies wollte ich nur vorweg nehmen damit niemand sofort fragt :"Suchfunktion benutzt ?"
Ich wäre über tipps, codes.... sehr dankbar.
Das ganze soll später über das VB programm anschasulich dargestellt werden und die Rundenzeiten etc. meine carrera anzeigen.
Ein Frohes Fest.
Gruß STefan
Hier mein Arduino Programm:
VB.NET-Quellcode
- /* StopWatch
- * Paul Badger 2008
- * Demonstrates using millis(), pullup resistors,
- * making two things happen at once, printing fractions
- *
- * Physical setup: momentary switch connected to pin 4, other side connected to ground
- * LED with series resistor between pin 13 and ground
- */
- #define ledPin A3 // LED connected to digital pin 13
- int Lichtschranke1 = A1; // oder Taster
- int Lichtschranke2 = A2;
- int Runde1 = 0;
- int Runde2 = 0;
- int Ton = 11;
- int value1 = LOW; // previous value of the LED
- int value2 = LOW; // previous value of the LED
- int buttonState1; // variable to store button state
- int buttonState2; // variable to store button state
- int lastButtonState1; // variable to store last button state
- int lastButtonState2; // variable to store last button state
- int blinking1; // condition for blinking - timer is timing
- int blinking2; // condition for blinking - timer is timing
- long interval1 = 100; // blink interval - change to suit
- long interval2 = 100; // blink interval - change to suit
- long previousMillis1 = 0; // variable to store last time LED was updated
- long previousMillis2 = 0; // variable to store last time LED was updated
- long start1 ; // start time for stop watch
- long dauer1 ; // elapsed time for stop watch
- long start2 ; // start time for stop watch
- long dauer2 ; // elapsed time for stop watch
- int fractional1; // variable used to store fractional part of time
- int fractional2; // variable used to store fractional part of time
- #include <LiquidCrystal.h>
- int Reset = 9;
- LiquidCrystal lcd(10,11,12,13,14,15,16);
- void setup()
- {
- lcd.begin(16, 2);
- pinMode(ledPin, OUTPUT); // sets the digital pin as output
- pinMode(Lichtschranke1, INPUT); // not really necessary, pins default to INPUT anyway
- pinMode(Lichtschranke2, INPUT); // not really necessary, pins default to INPUT anyway
- digitalWrite(Lichtschranke1, HIGH); // turn on pullup resistors. Wire button so that press shorts pin to ground.
- digitalWrite(Lichtschranke2, HIGH); // turn on pullup resistors. Wire button so that press shorts pin to ground.
- pinMode(Reset,INPUT);
- }
- void loop()
- {
- //LICHTSCHRANKE 2
- // check for button press
- buttonState2 = digitalRead(Lichtschranke2); // read the button state and store
- if (buttonState2 == LOW && lastButtonState2 == HIGH && blinking2 == false){ // check for a high to low transition
- // if true then found a new button press while clock is not running - start the clock
- start2 = millis(); // store the start time
- blinking2 = true; // turn on blinking while timing
- // short delay to debounce switch
- lastButtonState2 = buttonState2; // store buttonState in lastButtonState, to compare next time
- }
- else if (buttonState2 == LOW && lastButtonState2 == HIGH && blinking2 == true){ // check for a high to low transition
- // if true then found a new button press while clock is running - stop the clock and report
- Runde2++; // Inkrementieren der Variablen Runde
- dauer2 = millis() - start2; // store elapsed time
- blinking2 = false; // turn off blinking, all done timing
- Serial.begin(9600);
- Serial.print("Spieler 2 - Runde: ");
- Serial.print(Runde2);
- // routine to report elapsed time
- Serial.print(" Rundenzeit: ");
- Serial.print((int)(dauer2)/1000L); // divide by 1000 to convert to seconds - then cast to an int to print
- Serial.print("."); // print decimal point
- // use modulo operator to get fractional part of time
- fractional2 = (int)(dauer2 % 1000L);
- // pad in leading zeros - wouldn't it be nice if
- // Arduino language had a flag for this? :)
- if (fractional2 == 0)
- Serial.print("000"); // add three zero's
- else if (fractional2 < 10) // if fractional < 10 the 0 is ignored giving a wrong time, so add the zeros
- Serial.print("00"); // add two zeros
- else if (fractional2 < 100)
- Serial.print("0"); // add one zero
- if(digitalRead(Reset) == HIGH){
- Runde2=0;}
- Serial.println(fractional2); // print fractional part of time
- }
- else{
- lastButtonState2 = buttonState2; // store buttonState in lastButtonState, to compare next time
- }
- // blink routine - blink the LED while timing
- // check to see if it's time to blink the LED; that is, the difference
- // between the current time and last time we blinked the LED is larger than
- // the interval at which we want to blink the LED.
- if ( (millis() - previousMillis2 > interval2) ) {
- if (blinking2 == true){
- previousMillis2 = millis(); // remember the last time we blinked the LED
- // if the LED is off turn it on and vice-versa.
- if (value2 == LOW)
- value2 = HIGH;
- else
- value2 = LOW;
- digitalWrite(ledPin, value2);
- }
- else{
- digitalWrite(ledPin, LOW); // turn off LED when not blinking
- }
- }
- if(Runde2==20){
- digitalWrite(ledPin, HIGH);
- Runde2=0;
- Serial.print("");
- Serial.println("SPIELER 2 HAT GEWONNEN");
- delay(5000);}
- //LICHTSCHRANKE 1
- // check for button press
- buttonState1 = digitalRead(Lichtschranke1); // read the button state and store
- if (buttonState1 == LOW && lastButtonState1 == HIGH && blinking1 == false){ // check for a high to low transition
- // if true then found a new button press while clock is not running - start the clock
- start1 = millis(); // store the start time
- blinking1 = true; // turn on blinking while timing
- // short delay to debounce switch
- lastButtonState1 = buttonState1; // store buttonState in lastButtonState, to compare next time
- }
- else if (buttonState1 == LOW && lastButtonState1 == HIGH && blinking1 == true){ // check for a high to low transition
- // if true then found a new button press while clock is running - stop the clock and report
- Runde1++; // Inkrementieren der Variablen Runde
- dauer1 = millis() - start1; // store elapsed time
- blinking1 = false; // turn off blinking, all done timing
- Serial.begin(4800);
- Serial.print("Spieler 1 - Runde: ");
- Serial.print(Runde1);
- // routine to report elapsed time
- Serial.print(" Rundenzeit: ");
- Serial.print((int)(dauer1 / 1000L)); // divide by 1000 to convert to seconds - then cast to an int to print
- Serial.print("."); // print decimal point
- // use modulo operator to get fractional part of time
- fractional1 = (int)(dauer1 % 1000L);
- // pad in leading zeros - wouldn't it be nice if
- // Arduino language had a flag for this? :)
- if (fractional1 == 0)
- Serial.print("000"); // add three zero's
- else if (fractional1 < 10) // if fractional < 10 the 0 is ignored giving a wrong time, so add the zeros
- Serial.print("00"); // add two zeros
- else if (fractional1 < 100)
- Serial.print("0"); // add one zero
- Serial.print(fractional1);
- Serial.println("ms"); // print fractional part of time
- }
- else{
- lastButtonState1 = buttonState1; // store buttonState in lastButtonState, to compare next time
- }
- // blink routine - blink the LED while timing
- // check to see if it's time to blink the LED; that is, the difference
- // between the current time and last time we blinked the LED is larger than
- // the interval at which we want to blink the LED.
- if ( (millis() - previousMillis1 > interval1) ) {
- if (blinking1 == true){
- previousMillis1 = millis(); // remember the last time we blinked the LED
- // if the LED is off turn it on and vice-versa.
- if (value1 == LOW)
- value1 = HIGH;
- else
- value1 = LOW;
- digitalWrite(ledPin, value1);
- }
- else{
- digitalWrite(ledPin, LOW); // turn off LED when not blinking
- }
- }
- if(Runde1==20){
- Runde1=0;
- Serial.print("");
- Serial.println("SPIELER 1 HAT GEWONNEN");
- delay(5000);}
- }
Hier das VB Programm:
VB.NET-Quellcode
- Imports System.IO.Ports
- Public Class Form1
- Dim WithEvents sp As New SerialPort
- Private Sub GetSerialPortNames()
- sp.BaudRate = 4800
- sp.PortName = "COM4"
- sp.Open()
- End Sub
- Sub ShowString(ByVal myString As String)
- txtIn.AppendText(myString)
- End Sub
- Delegate Sub myMethodDelegate(ByVal [text] As String)
- Dim myDelegate As New myMethodDelegate(AddressOf ShowString)
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- GetSerialPortNames()
- End Sub
- Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
- Dim str As String = sp.ReadExisting()
- Invoke(myDelegate, str)
- End Sub
- Private Sub txtIn_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtIn.TextChanged
- End Sub
- End Class
*Posting ausgelagert*
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Marcus Gräfe“ ()