Post about your Basic project here

Moderator: Mmiscool

User avatar
By JMS
#66573 Here is the code that controls the POS cash register display. The display has an RS232 interface I have only connected the the RX and GND pin of the display and the 3.3v ttl serial drives it just fine (The display sends some unnecessary ,to me, data back but by eliminating the need to receive data I eliminated the need for a level shifter). By default it displays the time ,date, and the indoor/outdoor temp. It can also display an arbitrary message. I do not have a good picture of it at the moment or I would post one.

Code: Select all[screenFunctions]
topLine = chr(27) & "FA"  'string prefix to set top line
bottomLine = chr(27) & "FB" 'sting prefix to set bottomline
scrollTop = chr(27) & "FD" 'string prefix to set top line scrolling
scrollBottom = chr(27) & "FO"'string prefix to set bottom line scrolling

timer 60000, [getWeather] ' update weather every 10 mins
gosub [readTemp]

[main]
wprint "<meta name='viewport' content='width=device-width,initial-scale=1'><br>"
wprint "<center><h1>Local Control</h1><br>"
wprint "Line 1:"
textbox line1
wprint "<br>"
wprint "Line 2:"
textbox line2
wprint "<br>"
button "Submit", [displaySet]
button "Display Weather", [getWeather]
wprint "<br>" & "Inside Temp: " & inTemp
wait

[displaySet]
serial2begin 9600, 5 , 4
scrollYesNo1 = topLine
scrollYesNo2 = bottomLine
if len(line1) > 20 then
  scrollyesNo1 = scrollTop
endif
if len(line2) > 20 then
  scrollyesNo2 = scrollBottom
endif
serial2println scrollYesNo1 & line1
serial2println scrollYesNo2 & line2
SERIAL2END
wait

[getWeather]
let query = wget("api.openweathermap.org/data/2.5/weather?q=26554,us&appid="yourAppID"&units=imperial")
currentTemp = left(json(query,"main.temp"),2)
currentHumid = json(query,"main.humidity")
currentPressure = json(query,"main.pressure")
maxTemp = json(query,"main.temp_max")
minTemp = json(query,"main.temp_min")
let query = 0
gosub [readTemp]
gosub [fixTime]
line1 = "Out: " & currentTemp & chr(248) & " "& "In: " & inTemp & chr(248)
line2 = time("month-day-year") & " " & tHourMin
goto [displaySet]
wait

[readTemp] 'read temp from dsp18B20 module
cTemp = temp("28ffb726a2150367")
let inTemp = round((cTemp * 1.8 + 32)-9) 'convert to Fahrenheit  -9 because my 18b20 is not accurate
return

[fixTime] ' make the time look right on the display
tHour = time("hour")
tAmPm = "am"
if tHour > 12 then
 tHour = tHour - 12
 tAmPm = "pm"
end if
tHourMin = tHour & ":" & time("min") & tAmPm
return