Ledger Nano X - The secure hardware wallet
SHARE
TWEET

test

a guest Apr 7th, 2020 205 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- monitor prep
  2. mon = peripheral.wrap("left")
  3. mon.setTextScale(1)
  4. mon.setBackgroundColor(colors.black)
  5. mon.clear()
  6. -- defining variables
  7. b1 = 0
  8. b2 = 0
  9.  
  10. -- button creation function
  11. function button(x_pos, y_pos, x_end, y_end, text)
  12.     mon.setCursorPos(x_pos, y_pos)
  13.  mon.write(text)
  14. --  x_end, y_end = mon.getCursorPos()
  15.  
  16.  length = x_end - x_pos
  17.     height = y_end - y_pos
  18.  
  19.  return x_pos, y_pos, length, height
  20. end
  21.  
  22.  
  23. -- button 1 on click funct.
  24. function b1on(x_pos, y_pos, x_end, y_end, text, rs_side)
  25.  b1 = 1
  26.  mon.setBackgroundColor(colors.lime)
  27.  button(x_pos, y_pos, x_end, y_end, text)
  28.  rs.setOutput((rs_side), true)
  29.  
  30. end
  31.  
  32.  
  33. -- button 1 off click
  34. function b1off(x_pos, y_pos, x_end, y_end, text, rs_side)
  35.  b1 = 0
  36.  mon.setBackgroundColor(colors.red)
  37.  button(x_pos, y_pos, x_end, y_end, text)
  38.  rs.setOutput((rs_side), false)
  39.  
  40. end
  41.  
  42.  
  43. -- button 2 on click
  44. function b2on(x_pos, y_pos, x_end, y_end, text, rs_side)
  45.  b2 = 1
  46.  mon.setBackgroundColor(colors.lime)
  47.  button(x_pos, y_pos, x_end, y_end, text)
  48.  rs.setOutput((rs_side), true)
  49.  
  50. end
  51.  
  52.  
  53. --button 2 off click
  54. function b2off(x_pos, y_pos, x_end, y_end, text, rs_side)
  55.  b2 = 0
  56.  mon.setBackgroundColor(colors.red)
  57.  button(x_pos, y_pos, x_end, y_end, text)
  58.  rs.setOutput((rs_side), false)
  59.  
  60. end
  61.  
  62.  
  63. --button properties
  64. mon.setBackgroundColor(colors.red)
  65. b1_prop = { button(5, 10, 13, 10, " Hello there ") }
  66. b2_prop = { button(20, 10, 27, 10, " General Kenobi ") }
  67.  
  68. -- touch detect loop
  69. while true do
  70.     event, _, x_pos, y_pos = os.pullEvent("monitor_touch")
  71. --button 1 trigger
  72.     if x_pos >= b1_prop[1]
  73.  and x_pos <= b1_prop[3]
  74.  and y_pos >= b1_prop[2]
  75.  and y_pos <= b1_prop[4]
  76.  and b1 == 0
  77.  
  78.   then
  79.    b1on(5, 10, 13, 10, " Hello there ", "top")
  80.  
  81.  elseif
  82.  b1 == 1
  83.  then
  84.   b1off(5, 10, 13, 10, " Hello there ", "top")
  85.  
  86.  
  87. -- button 2 trigger
  88.  elseif x_pos >= b2_prop[1]
  89.  and x_pos <= b2_prop[3]
  90.  and y_pos >= b2_prop[2]
  91.  and y_pos <= b2_prop[4]
  92.  and b2 == 0  
  93.  
  94.   then
  95.    b2on(20, 10, 27, 10, " General Kenobi ", "right")
  96.    
  97.   elseif
  98.   b2 == 1
  99.    then
  100.     b2off(20, 10, 27, 10, " General Kenobi ", "right")
  101.  
  102. --else
  103.  
  104.  end
  105.  
  106.  
  107. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top