Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. --IO index ESP8266 pin IO index ESP8266 pin
  2. --0 [*] GPIO16 7 GPIO13
  3. --1 GPIO5 8 GPIO15
  4. --2 GPIO4 9 GPIO3
  5. --3 GPIO0 10 GPIO1
  6. --4 GPIO2 11 GPIO9
  7. --5 GPIO14 12 GPIO10
  8. --6 GPIO12
  9. --pk1=6 --led zielona
  10. --pk2=8 --led czerwona
  11. --pk3=7 --led niebieska
  12. pk4=1
  13.  
  14. pwm1=6 --LED ZIELONA
  15. pwm.setup(pwm1, 500, 512)
  16. pwm2=8 --LED CZERWONA
  17. pwm.setup(pwm2, 500, 512)
  18. pwm3=7 --LED NIEBIESKA
  19. pwm.setup(pwm3, 500, 512)
  20.  
  21. --gpio.mode(pk1, gpio.OUTPUT);
  22. --gpio.mode(pk2, gpio.OUTPUT);
  23. --gpio.mode(pk3, gpio.OUTPUT);
  24. gpio.mode(pk4, gpio.OUTPUT);
  25.  
  26. --gpio.write(pk1,gpio.LOW);
  27. --gpio.write(pk2,gpio.LOW);
  28. --gpio.write(pk3,gpio.LOW);
  29. gpio.write(pk4,gpio.LOW);
  30. zmpom1=0
  31. zmpom2=0
  32. zmpom3=0
  33. value=0
  34. uart.setup(0,9600,8,0,1)
  35. --==========================================
  36. print("Teraz skanuje adresy IP:")
  37. wifi.setmode(wifi.STATION)
  38. wifi.sta.config("SALA44","S@la44CkP");
  39. wifi.sta.setip({ip="192.168.44.106", netmask="255.255.255.0", gateway="192.168.44.1"})
  40. print("Konfiguracja skonczona, IP jest : "..wifi.sta.getip())
  41. tmr.delay(1000000)
  42. --==========================================
  43.  
  44. sv = net.createServer(net.TCP, 30)
  45.  
  46. function receiver(sck, data)
  47. --data=string.match(data,'GET /%s-..*%sHTTP/')
  48. str = string.sub(data,string.find(data,"GET /")
  49. +5,string.find(data,"HTTP/")-2)
  50.  
  51. print(str)
  52. if (str=="led1") then print("LED1") gpio.write(pk1,gpio.HIGH) end
  53. if (str=="led2") then print("LED2") gpio.write(pk1,gpio.LOW) end
  54. if (str=="led3") then print("LED3") gpio.write(pk2,gpio.LOW) end
  55. if (str=="led4") then print("LED4") gpio.write(pk2,gpio.HIGH) end
  56. if (str=="led5") then print("LED5") gpio.write(pk2,gpio.LOW)end
  57. if (str=="led6") then print("LED6") gpio.write(pk2,gpio.HIGH)end
  58. if (str=="led10") then print("pwm1") sciemnianie(1)end
  59. if (str=="led11") then print("pwm1") sciemnianie(2)end
  60. if (str=="led12") then print("pwm2") sciemnianie(3)end
  61. if (str=="led13") then print("pwm2") sciemnianie(4)end
  62. if (str=="led14") then print("pwm3") sciemnianie(5)end
  63. if (str=="led15") then print("pwm3") sciemnianie(6)end
  64. if (str=="exit") then file.remove("init.lua") end
  65. str=" "
  66. sck:close()
  67. end
  68. if sv then
  69. sv:listen(80, function(conn)
  70. conn:on("receive", receiver)
  71. conn:send("hello")
  72. end)
  73. end
  74.  
  75. --============================================================================================
  76. uart.on("data", "\r",
  77. function(data)
  78. print(recvdata)
  79. end, 0)
  80. --=====================================================================================
  81. function sciemnianie(szybkosc)
  82. if (szybkosc==1) then
  83. value=zmpom1
  84. if (value<500) then value=value+20 end
  85. pwm.setduty(pwm1, value)
  86. zmpom1=value
  87. end
  88. if (szybkosc==2) then
  89. value=zmpom1
  90. if(value>0) then value=value-20 end
  91. pwm.setduty(pwm1, value)
  92. zmpom1=value
  93. end
  94. if (szybkosc==3) then
  95. value=zmpom2
  96. if (value<500) then value=value+20 end
  97. pwm.setduty(pwm2, value)
  98. zmpom2=value
  99. end
  100. if (szybkosc==4) then
  101. value=zmpom2
  102. if(value>0) then value=value-20 end
  103. pwm.setduty(pwm2, value)
  104. zmpom2=value
  105. end
  106. if (szybkosc==5) then
  107. value=zmpom3
  108. if (value<500) then value=value+20 end
  109. pwm.setduty(pwm3, value)
  110. zmpom3=value
  111. end
  112. if (szybkosc==6) then
  113. value=zmpom3
  114. if(value>0) then value=value-20 end
  115. pwm.setduty(pwm3, value)
  116. zmpom3=value
  117.  
  118. end
  119. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement