Quantcast
Channel: Randy Riness @ SPSCC aggregator
Viewing all articles
Browse latest Browse all 3015

MSDN Blogs: Happy Birthday Small Basic – The 8th Anniversery

$
0
0

667D55F8-13D6-4615-8A28-0C4C6E3C73CB

Can you read the message on the LCD in this photo?  Happy Birthday, Small Basic!

Today’s Small Basic program is

' Send Text to Serial Port
' Version 0.1
' Copyright © 2016 Nonki Takahashi. The MIT License.
 
TextWindow.Title = "Send Text to Serial Port"
Init()
While "True"
  txt = TextWindow.Read()
  LDCommPort.TXString(txt + LF)
EndWhile
 
Sub Init
  LF = Text.GetCharacter(10)
  status = LDCommPort.OpenPort("COM3",9600)
  LDCommPort.SetEncoding("Ascii")
EndSub

And the Arduino sketch is

// LCD control via I2C from serial port#include<Wire.h>#include<LiquidCrystal_I2C.h>// Variable definitionconstintr=2;                     // rowsconstintc=16;                    // columnsLiquidCrystal_I2Clcd(0x3F,c,r);// set the LCD address to 0x3FStringinputString="";             // received stringbooleanstringComplete=false;      // received?voidsetup(){ lcd.init();                        // initialize the lcd  lcd.backlight(); Serial.begin(9600);}voidloop(){ if(stringComplete){   intlen=inputString.length();   lcd.clear();   if(len<= c){     lcd_print(inputString);   }else{     lcd_print(inputString.substring(0, c));     lcd.setCursor(0,1);     lcd_print(inputString.substring(c));   }   inputString="";   stringComplete=false; }}// Print string to LCDvoidlcd_print(Stringstr){ intlen=str.length(); for(inti=0;i<len;i++){   lcd.print(str.charAt(i)); }}// Serial event handlervoidserialEvent(){ while(Serial.available()){   charinChar=(char)Serial.read(); // read 1 byte   if(inChar=='n'){     // flag on if reseived newline     stringComplete=true;   }else{     inputString+=inChar; // append it to the string   } }}

See Also


Viewing all articles
Browse latest Browse all 3015

Trending Articles