/*
String to Integer conversion
Reads a serial input string until it sees a newline, then converts
the string to a number if the characters are digits.
The circuit:
No external components needed.
created 29 Nov 2010
by Tom Igoe
This example code is in the public domain.
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(23, 22,13,12,11,10);
String inString = ""; // string to hold input
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(19200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
lcd.begin(20, 4);
// send an intro:
//println("\n\nString toInt():");
//Serial.println();
}
void loop() {
// Read serial input:
while (Serial.available() > 0) {
lcd.setCursor(0,0);
lcd.print("welcome");
int inChar = Serial.read();
if (isDigit(inChar)) {
// convert the incoming byte to a char
// and add it to the string:
inString += (char)inChar;
}
// if you get a newline, print the string,
// then the string's value:
if (inChar == '\n') {
int data = inString.toInt() ;
lcd.setCursor(0,1);
lcd.print("speed: ");
lcd.println(data);
if(data > 50){
lcd.setCursor(0,2);
lcd.print("Over speed");
}
else{
lcd.setCursor(0,2);
lcd.print("Under speed limit ");
}
// Serial.print("Value:");
//Serial.println(inString.toInt());
//Serial.print("String: ");
//Serial.println(inString);
// clear the string for new input:
inString = "";
}
}
}
Serien Interfacing von Arduino mit Raspberry Pi-2-Daten digit
Dieser Code funktioniert zu übertragen, während mit Arduino mit seriellem Monitor, aber als Schnittstelle Arduino mit Raspberry Pi lief, nur "Willkommen" Meldung kam auf LCD nicht Daten (2-stellige Nummer), die ich über Raspberry Pi übertragen habe, möglicherweise liegt es an Python-Programm auf Raspberry Pi oder einem anderen Grund.
Hast du ernsthaft nur ein Foto von einem Bildschirm nahm, anstatt nur einfach kopieren Sie den Code einfügen? Warum? –
Weil ich nicht paste python code von R pi auf meinen Laptop kopieren kann = D;) – Saddaqat