楼主: ReneeBK
843 9

【GitHub】Internet of Things with Python [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49407 个
通用积分
51.8704
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. #Internet of Things with Python

  2. This is the code repository for Internet of Things with Python, published by Packt. It contains all the supporting project files necessary to work through the book from start to finish.

  3. ##Instructions and Navigation

  4. The code included with this book is meant for use as an aid in performing the exercises and should not be used as a replacement for the book itself. Used out of context, the code may result in an unusable configuration and no warranty is given.

  5. The code will look like the following:
  6. class NumberInLeds:
  7.     def __init__(self):
  8.         self.leds = []
  9.         for i in range(9, 0, -1):
  10.             led = Led(i, 10 - i)
  11.             self.leds.append(led)

  12.     def print_number(self, number):
  13.         print("==== Turning on {0} LEDs ====".format(number))
  14.         for j in range(0, number):
  15.             self.leds[j].turn_on()
  16.         for k in range(number, 9):
  17.             self.leds[k].turn_off()


  18. if __name__ == "__main__":
  19.     print ("Working with wiring-x86 on Intel Galileo Gen 2")

  20.     number_in_leds = NumberInLeds()
  21.     # Count from 0 to 9
  22.     for i in range(0, 10):
  23.         number_in_leds.print_number(i)
  24.         time.sleep(3)
复制代码

本帖隐藏的内容

Internet-of-Things-with-Python-master.zip (1.37 MB)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Internet Things Intern GitHub python

沙发
ReneeBK 发表于 2017-5-20 11:10:50 |只看作者 |坛友微信交流群
  1. __author__ = 'Gaston C. Hillar'


  2. import mraa
  3. import time


  4. if __name__ == "__main__":
  5.     print ("Mraa library version: {0}".format(mraa.getVersion()))
  6.     print ("Mraa detected platform name: {0}".format(mraa.getPlatformName()))

  7.     # Configure GPIO pin #13 to be an output pin
  8.     onboard_led = mraa.Gpio(13)
  9.     onboard_led.dir(mraa.DIR_OUT)

  10.     while True:
  11.         # Turn on the onboard LED
  12.         onboard_led.write(1)
  13.         print("I've turned on the onboard LED.")
  14.         # Sleep 3 seconds
  15.         time.sleep(3)
  16.         # Turn off the onboard LED
  17.         onboard_led.write(0)
  18.         print("I've turned off the onboard LED.")
  19.         time.sleep(2)
复制代码

使用道具

藤椅
ReneeBK 发表于 2017-5-20 11:11:17 |只看作者 |坛友微信交流群
  1. __author__ = 'Gaston C. Hillar'


  2. import mraa
  3. import time


  4. if __name__ == "__main__":
  5.     print ("Mraa library version: {0}".format(mraa.getVersion()))
  6.     print ("Mraa detected platform name: {0}".format(mraa.getPlatformName()))

  7.     # Configure GPIO pins #1 to 9 to be output pins
  8.     output = []
  9.     for i in range(1, 10):
  10.         gpio = mraa.Gpio(i)
  11.         gpio.dir(mraa.DIR_OUT)
  12.         output.append(gpio)

  13.     # Count from 1 to 9
  14.     for i in range(1, 10):
  15.         print("==== Turning on {0} LEDs ====".format(i))
  16.         for j in range(0, i):
  17.             output[j].write(1)
  18.             print("I've turned on the LED connected to GPIO Pin #{0}.".format(j + 1))
  19.         time.sleep(3)
复制代码

使用道具

板凳
ReneeBK 发表于 2017-5-20 11:11:47 |只看作者 |坛友微信交流群
  1. __author__ = 'Gaston C. Hillar'


  2. import mraa
  3. import time


  4. class Led:
  5.     def __init__(self, pin):
  6.         self.gpio = mraa.Gpio(pin)
  7.         self.gpio.dir(mraa.DIR_OUT)

  8.     def turn_on(self):
  9.         self.gpio.write(1)
  10.         print("I've turned on the LED connected to GPIO Pin #{0}.".format(self.gpio.getPin()))


  11.     def turn_off(self):
  12.         self.gpio.write(0)
  13.         print("I've turned off the LED connected to GPIO Pin #{0}.".format(self.gpio.getPin()))


  14. if __name__ == "__main__":
  15.     print ("Mraa library version: {0}".format(mraa.getVersion()))
  16.     print ("Mraa detected platform name: {0}".format(mraa.getPlatformName()))

  17.     # Configure GPIO pins #1 to 9 to be output pins
  18.     leds = []
  19.     for i in range(1, 10):
  20.         led = Led(i)
  21.         leds.append(led)

  22.     # Count from 1 to 9
  23.     for i in range(1, 10):
  24.         print("==== Turning on {0} LEDs ====".format(i))
  25.         for j in range(0, i):
  26.             leds[j].turn_on()
  27.         for k in range(i, 9):
  28.             leds[k].turn_off()
  29.         time.sleep(10)
复制代码

使用道具

报纸
ReneeBK 发表于 2017-5-20 11:12:18 |只看作者 |坛友微信交流群
  1. __author__ = 'Gaston C. Hillar'


  2. import mraa
  3. import time


  4. class Led:
  5.     def __init__(self, pin):
  6.         self.gpio = mraa.Gpio(pin)
  7.         self.gpio.dir(mraa.DIR_OUT)

  8.     def turn_on(self):
  9.         self.gpio.write(1)
  10.         print("I've turned on the LED connected to GPIO Pin #{0}.".format(self.gpio.getPin()))


  11.     def turn_off(self):
  12.         self.gpio.write(0)
  13.         print("I've turned off the LED connected to GPIO Pin #{0}.".format(self.gpio.getPin()))


  14. class NumberInLeds:
  15.     def __init__(self):
  16.         self.leds = []
  17.         for i in range(1, 10):
  18.             led = Led(i)
  19.             self.leds.append(led)

  20.     def print_number(self, number):
  21.         print("==== Turning on {0} LEDs ====".format(number))
  22.         for j in range(0, number):
  23.             self.leds[j].turn_on()
  24.         for k in range(number, 9):
  25.             self.leds[k].turn_off()

  26. if __name__ == "__main__":
  27.     print ("Mraa library version: {0}".format(mraa.getVersion()))
  28.     print ("Mraa detected platform name: {0}".format(mraa.getPlatformName()))

  29.     number_in_leds = NumberInLeds()
  30.     # Count from 0 to 9
  31.     for i in range(0, 10):
  32.         number_in_leds.print_number(i)
  33.         time.sleep(3)
复制代码

使用道具

地板
fengyg 企业认证  发表于 2017-5-20 11:56:56 |只看作者 |坛友微信交流群
kankan

使用道具

7
zhaosl 发表于 2017-5-20 12:38:52 |只看作者 |坛友微信交流群

使用道具

8
ekscheng 发表于 2017-5-20 17:36:27 |只看作者 |坛友微信交流群

使用道具

9
ithjesuxf 发表于 2017-5-21 13:38:31 |只看作者 |坛友微信交流群
thanks for sharing

使用道具

10
lianqu 发表于 2017-8-17 10:48:27 |只看作者 |坛友微信交流群

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 00:06