Questions with regards to ESP8266 Basic and hardware interfacing and control via Basic commands

Moderator: Mmiscool

User avatar
By tcpipchip
#54697
Code: Select alltft.touch.setup(15)
tft.setup(16, 4, 1)

bar1 = tft.obj.bar("RPM",200,0,120,30, 2, 65535, tft.rgb(0,25,255))
bar2 = tft.obj.bar("TEMPERA",200,50,120,30, 2, 65535, tft.rgb(0,25,255))
bar3 = tft.obj.bar("VELOCID",200,100,120,30, 2, 65535, tft.rgb(0,25,255))
bar4 = tft.obj.bar("AIRFLOW",200,150,120,30, 2, 65535, tft.rgb(0,25,255))
bar5 = tft.obj.bar("POSITION",200,200,120,30, 2, 65535, tft.rgb(0,25,255))

tft.bmp("/uploads/red_512.bmp",30,0,0)

tft.text.cursor(160,5)
tft.print("RPM")
tft.text.cursor(160,55)
tft.print("TMP")
tft.text.cursor(160,105)
tft.print("VEL")
tft.text.cursor(160,155)
tft.print("MAF")
tft.text.cursor(160,205)
tft.print("POS")

but1 = tft.obj.button("SEL", 5,110,150,70,4)

tft.obj.setlabel(but1,"0000")

Telnetbranch [obdii]

aaa = telnet.client.connect("192.168.1.111", 35000)
aaa = telnet.client.write("ATE0" & chr(13))

PID = 0
OPTION = 1
tft.obj.setvalue(bar1, 100)

Timer 50, [rpm]

touchbranch [touchme]

wait

[touchme]
touch_obj = tft.checktouch()
if touch_obj = but1 then

  tft.obj.invert(but1)

  OPTION = OPTION + 1
  if OPTION = 6 then
     OPTION = 1
  end if

  if OPTION = 1 then
     tft.obj.setvalue(bar1, 100)
  else
     tft.obj.setvalue(bar1, 0)
  end if

  if OPTION = 2 then
     tft.obj.setvalue(bar2, 100)
  else
     tft.obj.setvalue(bar2, 0)
  end if

  if OPTION = 3 then
     tft.obj.setvalue(bar3, 100)
  else
     tft.obj.setvalue(bar3, 0)
  end if

  if OPTION = 4 then
     tft.obj.setvalue(bar4, 100)
  else
     tft.obj.setvalue(bar4, 0)
  end if

  if OPTION = 5 then
     tft.obj.setvalue(bar5, 100)
  else
     tft.obj.setvalue(bar5, 0)
  end if

end if
return

[obdii]
tcp = telnet.client.read.str()
tam = len(tcp)
if tam = 16 or tam = 13 then
   cmd = mid(tcp,6,2)
   if cmd = "0C" then
      tcp = hextoint(replace(mid(tcp,9,5)," ",""))
      tcp = str(int(tcp / 4))
      tft.obj.setlabel(bar1, tcp)
      if OPTION = 1 then
         tft.obj.setlabel(but1,tcp)
      end if
   end if
   if cmd = "05" then
      tcp = hextoint(replace(mid(tcp,9,5)," ",""))
      tcp = str(int(tcp) - 40)
      tft.obj.setlabel(bar2, tcp)
      if OPTION = 2 then
         tft.obj.setlabel(but1,tcp)
      end if
   end if
   if cmd = "0D" then
      tcp = hextoint(replace(mid(tcp,9,5)," ",""))
      tcp = str(int(tcp))
      tft.obj.setlabel(bar3, tcp)
      if OPTION = 3 then
         tft.obj.setlabel(but1,tcp)
      end if
   end if
   if cmd = "10" then
      tcp = hextoint(replace(mid(tcp,9,5)," ",""))
      tcp = str(int(tcp / 100))
      tft.obj.setlabel(bar4, tcp)
      if OPTION = 4 then
         tft.obj.setlabel(but1,tcp)
      end if
   end if
   if cmd = "11" then
      tcp = hextoint(replace(mid(tcp,9,5)," ",""))
      tcp = str(int(tcp * 0.392156))
      tft.obj.setlabel(bar5, tcp)
      if OPTION = 5 then
         tft.obj.setlabel(but1,tcp)
      end if
   end if
end if

wait

[rpm]
PID = PID + 1
if PID = 6 then
   PID = 0
end if
if PID = 1 then
   aaa = telnet.client.write("01 0C" & chr(13))
end if
if PID = 2 then
   aaa = telnet.client.write("01 05" & chr(13))
end if
if PID = 3 then
   aaa = telnet.client.write("01 0D" & chr(13))
end if
if PID = 4 then
   aaa = telnet.client.write("01 10" & chr(13))
end if
if PID = 5 then
   aaa = telnet.client.write("01 11" & chr(13))
end if
wait


many times only write 2 or 3 bars and crash!
User avatar
By Mmiscool
#54712 Are you using the latest build? There was a problem with the timer that got fixed in the latest.