次の方法で共有


Happy Birthday Small Basic - The 8th Anniversary

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 definition
const int r = 2;                      // rows
const int c = 16;                     // columns
LiquidCrystal_I2C lcd(0x3F, c, r); // set the LCD address to 0x3F
String inputString = "";              // received string
boolean stringComplete = false;       // received?

void setup()
{
  lcd.init();                         // initialize the lcd 
  lcd.backlight();
  Serial.begin(9600);
}

void loop() {
  if (stringComplete) {
    int len = 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 LCD
void lcd_print(String str) {
  int len = str.length();
  for (int i = 0; i < len; i++) {
    lcd.print(str.charAt(i)); 
  }
}

// Serial event handler
void serialEvent() {
  while (Serial.available()) {
    char inChar = (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

Comments

  • Anonymous
    October 23, 2016
    Allways articles with great value !
  • Anonymous
    October 23, 2016
    I so want to see the next version of Small Basic, v1.3 i guess. I'm looking forward to try it !!I am certain that they will be several new functions, commands, instructions which will be added to the base engine. Congratulations Microsoft for this great free software that makes us return to our passions of amateur programmers. !Here is according to (wiki) the version history:2008-10-23 V0.1 released 2008-12-17 V0.2 released 2009-02-10 V0.3 released 2009-04-14 V0.4 released 2009-06-16 V0.5 released 2009-08-19 V0.6 released 2009-10-23 V0.7 released 2010-02-04 V0.8 released 2010-06-11 V0.9 released 2010-11-17 V0.91 released 2011-02-08 V0.95 released2011-07-12 V1.0 released2015-03-27 V1.1 released2015-10-01 V1.2 released
    • Anonymous
      October 23, 2016
      wishlist for v 1.3:-constants-replace cmd-functions-subs with args-local vars-debugger-include external files (like $I directive)-publish pics-background color change for edit window
      • Anonymous
        October 23, 2016
        also code hiding/expanding blocks, very welcome for long listingsi find sb ide ++ but it's just for sb1.0(( can it be updated for sb v1.2?
      • Anonymous
        October 23, 2016
        my wishlist to Santa Claus for SB V1.3 :))Sound.playmusic ( lenght of notes 1 to 64 to 1 to 128)Sound.playmusic ( possibilities to play 4 notes in the same time , to program chords )an simple alternative graphicswindow command to textwindow.read(), like graphicswindow.read() , to enter keyboard data intercative.a no border graphicswindow ( full screen)a way for MATH to handle bigger number like 10 power 75 , ex: ( Sun mass 10^30 multiply by Earth mass 10^24 ) = 10^54 , gravitational law computing.and finally and finally, to improve the speed of the setpixel command.
        • Anonymous
          October 24, 2016
          setpixel speedup is already done in ld xtension by LDImage.GetWorkingImagePixel and LDImage.SetWorkingImagePixel also can be done by 2d matrix LDImage.GetImagePixels and LDImage.SetImagePixels
          • Anonymous
            October 24, 2016
            The comment has been removed
          • Anonymous
            October 25, 2016
            u should use the ms paint.net app then, which uses c# language and scripts to control each pixel very fast
          • Anonymous
            October 29, 2016
            I got some push back from our community council and teachers about adding more into the core library that's currently available as extensions. We'll get some new data in the future and see if we want to make that request again. But one solution is the Extension Manager, which makes it easier to find, install, and turn on/off extensions.
        • Anonymous
          October 29, 2016
          These are some good suggestions.Can you add these to the list? http://social.technet.microsoft.com/wiki/contents/articles/24082.microsoft-small-basic-v1-0-known-issues.aspx#Feature_IdeasThanks!
      • Anonymous
        October 29, 2016
        The comment has been removed
    • Anonymous
      October 29, 2016
      That's right! Nice bit of history! Our biggest improvement for 1.3 is a web version!
  • Anonymous
    October 23, 2016
    Hi Nonki,just a little things, for your main title of this article:the word anniversary is written like this: anniversary :)
    • Anonymous
      October 29, 2016
      Thanks, Yled!
  • Anonymous
    October 23, 2016
    YLed, thank you for your comments. I will fix the title.Tryhest, I will copy your wish list to a wiki article. Thanks.
  • Anonymous
    October 29, 2016
    8 years! Wow!