Enviar pesquisa
Carregar
Livraria Sense hat - resumo
•
2 gostaram
•
664 visualizações
Ana Carneirinho
Seguir
Funções básicas associadas à livraria SenseHat (projeto Astro Pi)
Leia menos
Leia mais
Educação
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 5
Baixar agora
Baixar para ler offline
Recomendados
Python basic
Python basic
sewoo lee
Python Programming: Data Structure
Python Programming: Data Structure
Chan Shik Lim
Data structures lab
Data structures lab
Ragu Ram
Introduction to python programming 2
Introduction to python programming 2
Giovanni Della Lunga
Introduction to python programming 1
Introduction to python programming 1
Giovanni Della Lunga
Astro Pi - Explorando o Sense Hat
Astro Pi - Explorando o Sense Hat
Ana Carneirinho
Astro Pi - introdução ao Python
Astro Pi - introdução ao Python
Ana Carneirinho
Astro pi - Como recolher dados do astro Pi
Astro pi - Como recolher dados do astro Pi
Ana Carneirinho
Recomendados
Python basic
Python basic
sewoo lee
Python Programming: Data Structure
Python Programming: Data Structure
Chan Shik Lim
Data structures lab
Data structures lab
Ragu Ram
Introduction to python programming 2
Introduction to python programming 2
Giovanni Della Lunga
Introduction to python programming 1
Introduction to python programming 1
Giovanni Della Lunga
Astro Pi - Explorando o Sense Hat
Astro Pi - Explorando o Sense Hat
Ana Carneirinho
Astro Pi - introdução ao Python
Astro Pi - introdução ao Python
Ana Carneirinho
Astro pi - Como recolher dados do astro Pi
Astro pi - Como recolher dados do astro Pi
Ana Carneirinho
EV3#5: Exercicios com o sensor cor
EV3#5: Exercicios com o sensor cor
Ana Carneirinho
EV3#6: Exercicios com o sensor rotação
EV3#6: Exercicios com o sensor rotação
Ana Carneirinho
EV3#4: Exercicios com o sensor de toque
EV3#4: Exercicios com o sensor de toque
Ana Carneirinho
EV3#1: Blocos fundamentais
EV3#1: Blocos fundamentais
Ana Carneirinho
Arduino - iniciação à linguagem C: LCD 1602
Arduino - iniciação à linguagem C: LCD 1602
Ana Carneirinho
EV3#3: Exercicios com o sensor de ultrassons
EV3#3: Exercicios com o sensor de ultrassons
Ana Carneirinho
Workshop Arduino + Scratch
Workshop Arduino + Scratch
Ana Carneirinho
Lâmpada controlada por relé e arduino programado em S4A
Lâmpada controlada por relé e arduino programado em S4A
Ana Carneirinho
Estudo orientado de circuitos com motor dc programados em S4A
Estudo orientado de circuitos com motor dc programados em S4A
Ana Carneirinho
Arduino - iniciação à linguagem C (entradas e saídas digitais)
Arduino - iniciação à linguagem C (entradas e saídas digitais)
Ana Carneirinho
EV3#7: Exercicios seguidor de linha
EV3#7: Exercicios seguidor de linha
Ana Carneirinho
Arduino - iniciação à linguagem C (servomotores)
Arduino - iniciação à linguagem C (servomotores)
Ana Carneirinho
EV3#2: Exercícios introdutórios
EV3#2: Exercícios introdutórios
Ana Carneirinho
Programação de arduinos com S4A (exercícios com entradas e saídas digitais)
Programação de arduinos com S4A (exercícios com entradas e saídas digitais)
Ana Carneirinho
LED RGB e saída PWM - estudo orientado com S4A
LED RGB e saída PWM - estudo orientado com S4A
Ana Carneirinho
The can sat_book_2016-2017_versienov2016
The can sat_book_2016-2017_versienov2016
Ana Carneirinho
Programando em python modulos
Programando em python modulos
samuelthiago
Ensinando Computação e Fazendo Ciência com Python
Ensinando Computação e Fazendo Ciência com Python
Luiz Cláudio Silva
Python - o que, porque, como e quando
Python - o que, porque, como e quando
Gustavo Carvalho
Espaço Programação e Eletrónica - Sessão4
Espaço Programação e Eletrónica - Sessão4
Ana Carneirinho
Introducing Reactive Machine Learning
Introducing Reactive Machine Learning
Jeff Smith
Class 26: Objectifying Objects
Class 26: Objectifying Objects
David Evans
Mais conteúdo relacionado
Destaque
EV3#5: Exercicios com o sensor cor
EV3#5: Exercicios com o sensor cor
Ana Carneirinho
EV3#6: Exercicios com o sensor rotação
EV3#6: Exercicios com o sensor rotação
Ana Carneirinho
EV3#4: Exercicios com o sensor de toque
EV3#4: Exercicios com o sensor de toque
Ana Carneirinho
EV3#1: Blocos fundamentais
EV3#1: Blocos fundamentais
Ana Carneirinho
Arduino - iniciação à linguagem C: LCD 1602
Arduino - iniciação à linguagem C: LCD 1602
Ana Carneirinho
EV3#3: Exercicios com o sensor de ultrassons
EV3#3: Exercicios com o sensor de ultrassons
Ana Carneirinho
Workshop Arduino + Scratch
Workshop Arduino + Scratch
Ana Carneirinho
Lâmpada controlada por relé e arduino programado em S4A
Lâmpada controlada por relé e arduino programado em S4A
Ana Carneirinho
Estudo orientado de circuitos com motor dc programados em S4A
Estudo orientado de circuitos com motor dc programados em S4A
Ana Carneirinho
Arduino - iniciação à linguagem C (entradas e saídas digitais)
Arduino - iniciação à linguagem C (entradas e saídas digitais)
Ana Carneirinho
EV3#7: Exercicios seguidor de linha
EV3#7: Exercicios seguidor de linha
Ana Carneirinho
Arduino - iniciação à linguagem C (servomotores)
Arduino - iniciação à linguagem C (servomotores)
Ana Carneirinho
EV3#2: Exercícios introdutórios
EV3#2: Exercícios introdutórios
Ana Carneirinho
Programação de arduinos com S4A (exercícios com entradas e saídas digitais)
Programação de arduinos com S4A (exercícios com entradas e saídas digitais)
Ana Carneirinho
LED RGB e saída PWM - estudo orientado com S4A
LED RGB e saída PWM - estudo orientado com S4A
Ana Carneirinho
The can sat_book_2016-2017_versienov2016
The can sat_book_2016-2017_versienov2016
Ana Carneirinho
Programando em python modulos
Programando em python modulos
samuelthiago
Ensinando Computação e Fazendo Ciência com Python
Ensinando Computação e Fazendo Ciência com Python
Luiz Cláudio Silva
Python - o que, porque, como e quando
Python - o que, porque, como e quando
Gustavo Carvalho
Espaço Programação e Eletrónica - Sessão4
Espaço Programação e Eletrónica - Sessão4
Ana Carneirinho
Destaque
(20)
EV3#5: Exercicios com o sensor cor
EV3#5: Exercicios com o sensor cor
EV3#6: Exercicios com o sensor rotação
EV3#6: Exercicios com o sensor rotação
EV3#4: Exercicios com o sensor de toque
EV3#4: Exercicios com o sensor de toque
EV3#1: Blocos fundamentais
EV3#1: Blocos fundamentais
Arduino - iniciação à linguagem C: LCD 1602
Arduino - iniciação à linguagem C: LCD 1602
EV3#3: Exercicios com o sensor de ultrassons
EV3#3: Exercicios com o sensor de ultrassons
Workshop Arduino + Scratch
Workshop Arduino + Scratch
Lâmpada controlada por relé e arduino programado em S4A
Lâmpada controlada por relé e arduino programado em S4A
Estudo orientado de circuitos com motor dc programados em S4A
Estudo orientado de circuitos com motor dc programados em S4A
Arduino - iniciação à linguagem C (entradas e saídas digitais)
Arduino - iniciação à linguagem C (entradas e saídas digitais)
EV3#7: Exercicios seguidor de linha
EV3#7: Exercicios seguidor de linha
Arduino - iniciação à linguagem C (servomotores)
Arduino - iniciação à linguagem C (servomotores)
EV3#2: Exercícios introdutórios
EV3#2: Exercícios introdutórios
Programação de arduinos com S4A (exercícios com entradas e saídas digitais)
Programação de arduinos com S4A (exercícios com entradas e saídas digitais)
LED RGB e saída PWM - estudo orientado com S4A
LED RGB e saída PWM - estudo orientado com S4A
The can sat_book_2016-2017_versienov2016
The can sat_book_2016-2017_versienov2016
Programando em python modulos
Programando em python modulos
Ensinando Computação e Fazendo Ciência com Python
Ensinando Computação e Fazendo Ciência com Python
Python - o que, porque, como e quando
Python - o que, porque, como e quando
Espaço Programação e Eletrónica - Sessão4
Espaço Programação e Eletrónica - Sessão4
Semelhante a Livraria Sense hat - resumo
Introducing Reactive Machine Learning
Introducing Reactive Machine Learning
Jeff Smith
Class 26: Objectifying Objects
Class 26: Objectifying Objects
David Evans
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
PROIDEA
MCL333_Building Deep Learning Applications with TensorFlow on AWS
MCL333_Building Deep Learning Applications with TensorFlow on AWS
Amazon Web Services
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB
Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012
Wen-Wei Liao
Session 09 learning relationships.pptx
Session 09 learning relationships.pptx
Sara-Jayne Terp
Session 09 learning relationships.pptx
Session 09 learning relationships.pptx
bodaceacat
Python seaborn cheat_sheet
Python seaborn cheat_sheet
Nishant Upadhyay
Python ppt
Python ppt
AMIT VIRAMGAMI
Assignment 6.1.pdf
Assignment 6.1.pdf
dash41
python modules1522.pdf
python modules1522.pdf
DebanjanMaity13
Chapter01_Python.ppt
Chapter01_Python.ppt
PigPug1
Lsl scripts
Lsl scripts
Giovanna Sardo
Java Simple Programs
Java Simple Programs
Upender Upr
Blaise_UK_109_Max Kleiner_image2textAPI.pdf
Blaise_UK_109_Max Kleiner_image2textAPI.pdf
breitschbreitsch
Advanced Java - Practical File
Advanced Java - Practical File
Fahad Shaikh
java set1 program.pdf
java set1 program.pdf
722820106121SARANS
Semelhante a Livraria Sense hat - resumo
(18)
Introducing Reactive Machine Learning
Introducing Reactive Machine Learning
Class 26: Objectifying Objects
Class 26: Objectifying Objects
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
MCL333_Building Deep Learning Applications with TensorFlow on AWS
MCL333_Building Deep Learning Applications with TensorFlow on AWS
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012
Session 09 learning relationships.pptx
Session 09 learning relationships.pptx
Session 09 learning relationships.pptx
Session 09 learning relationships.pptx
Python seaborn cheat_sheet
Python seaborn cheat_sheet
Python ppt
Python ppt
Assignment 6.1.pdf
Assignment 6.1.pdf
python modules1522.pdf
python modules1522.pdf
Chapter01_Python.ppt
Chapter01_Python.ppt
Lsl scripts
Lsl scripts
Java Simple Programs
Java Simple Programs
Blaise_UK_109_Max Kleiner_image2textAPI.pdf
Blaise_UK_109_Max Kleiner_image2textAPI.pdf
Advanced Java - Practical File
Advanced Java - Practical File
java set1 program.pdf
java set1 program.pdf
Mais de Ana Carneirinho
Arduino - iniciação à linguagem C (entradas analógica)
Arduino - iniciação à linguagem C (entradas analógica)
Ana Carneirinho
Projeto Casa Inteligente (Arduino e Snap4Arduino)
Projeto Casa Inteligente (Arduino e Snap4Arduino)
Ana Carneirinho
Circuitos com Sensor PIR (Arduino e S4A)
Circuitos com Sensor PIR (Arduino e S4A)
Ana Carneirinho
BlocklyDuino e mBlock - um estudo comparativo
BlocklyDuino e mBlock - um estudo comparativo
Ana Carneirinho
Movimento obliquo - simulação (arduino e S4A)
Movimento obliquo - simulação (arduino e S4A)
Ana Carneirinho
Espaço Programação e Eletrónica - Sessão5
Espaço Programação e Eletrónica - Sessão5
Ana Carneirinho
Controlo de motor de passo com Snap4Arduino
Controlo de motor de passo com Snap4Arduino
Ana Carneirinho
Termómetro (Arduino & Scractch)
Termómetro (Arduino & Scractch)
Ana Carneirinho
Projeto de S. Valentim
Projeto de S. Valentim
Ana Carneirinho
Espaço Programação e Eletrónica - Sessão 3
Espaço Programação e Eletrónica - Sessão 3
Ana Carneirinho
Mais de Ana Carneirinho
(10)
Arduino - iniciação à linguagem C (entradas analógica)
Arduino - iniciação à linguagem C (entradas analógica)
Projeto Casa Inteligente (Arduino e Snap4Arduino)
Projeto Casa Inteligente (Arduino e Snap4Arduino)
Circuitos com Sensor PIR (Arduino e S4A)
Circuitos com Sensor PIR (Arduino e S4A)
BlocklyDuino e mBlock - um estudo comparativo
BlocklyDuino e mBlock - um estudo comparativo
Movimento obliquo - simulação (arduino e S4A)
Movimento obliquo - simulação (arduino e S4A)
Espaço Programação e Eletrónica - Sessão5
Espaço Programação e Eletrónica - Sessão5
Controlo de motor de passo com Snap4Arduino
Controlo de motor de passo com Snap4Arduino
Termómetro (Arduino & Scractch)
Termómetro (Arduino & Scractch)
Projeto de S. Valentim
Projeto de S. Valentim
Espaço Programação e Eletrónica - Sessão 3
Espaço Programação e Eletrónica - Sessão 3
Último
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
Jisc
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
Dr. Ravikiran H M Gowda
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
marlenawright1
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
agholdier
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
annathomasp01
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Dr Vijay Vishwakarma
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
MaryamAhmad92
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
Celine George
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
Mebane Rash
Single or Multiple melodic lines structure
Single or Multiple melodic lines structure
dhanjurrannsibayan2
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
Pooja Bhuva
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
camerronhm
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
Amil baba
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
Nguyen Thanh Tu Collection
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
christianmathematics
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
jbellavia9
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
Celine George
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Pooja Bhuva
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Pooja Bhuva
Último
(20)
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
Single or Multiple melodic lines structure
Single or Multiple melodic lines structure
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Livraria Sense hat - resumo
1.
Enablingthe AstroPimission SenseHat Python3Cheatsheet ToaddSenseHATfunctionalitytoyourpythonprogramsaddthefollowinglinestoimportthelibraryfortheSenseHAT library: fromsense_hatimportSenseHat sense=SenseHat() FromthatpointforwardsyoucanuseanyofthesetoffunctionsfromtheSenseHATLibrary. sense.set_pixel(0,0,255,0,0) SetsthetopleftLEDtothecolourred. sense.show_letter(“J”,0,0,255) Displaystheletter“J”onthescreeninblue. sense.show_message(“msg”,text_colour=[0,255,0])
Displaysthemessage“msg”onthematrixingreen. sense.load_image(“creeper.png”,redraw=True) Loadan8x8image“creeper.png”imageanddisplayit. sense.clear() ClearstheLEDandswitchesthemalloff. sense.set_rotation(r=0) SetstherotationoftheLEDmatrix. sense.set_pixels(pixelList) Usespixellisttodrawapicture,eachitemisan[R,G,B]list yaw,pitch,roll=sense.get_orientation().values() Getstheorientationdataandstorestheirvaluesasyaw,pitch, roll m_x,m_y,m_z=sense.get_compass_raw().values() Getsthecompassdataandstores asm_x,m_y,m_z x,y,z=sense.get_accelerometer_raw().values() Getstheaccelerometerdataandstoresasx,y,z g_x,g_y,g_z=sense.get_gyroscope_raw().values() Getstheorientationdataandstoresasg_x,g_y,g_z
2.
t=sense.get_temperature_from_humidity() Usesthehumiditysensortogettemperatureandstoresitast. t=sense.get_temperature_from_pressure() Usesthepressuresensortogettemperatureandstoresitast. h=sense.get_humidity()
Measuresthehumidityandstoresitash. p=sense.get_pressure() Measuresthepressureandstoresitasp. Thereareanumberofwaystocapturetheinputfromthejoystick.Youcouldusetheeitherthepygameorcurses library.Howeverforthisexamplewe’regoingtousetheevdevsystem,whichyou’llneedtoinstallusing“sudopip3 installevdev” fromevdevimportInputDevice,ecodes,list_devices fromselectimportselect devices=[InputDevice(fn)forfninlist_devices()] fordevindevices: ifdev.name=="RaspberryPiSenseHATJoystick": js=dev whileTrue: r,w,x=select([dev.fd],[],[],0.01) forfdinr: foreventindev.read(): ifevent.type==ecodes.EV_KEY:#andevent.value==1: ifevent.code==ecodes.KEY_UP: print("up") elifevent.code==ecodes.KEY_LEFT: print("left") elifevent.code==ecodes.KEY_RIGHT: print("right") elifevent.code==ecodes.KEY_DOWN: print("down") else: print("enter") Thecodeontheleftlooksthroughthe availableinputdevicesandfindstheSense-HAT joystick. Itthencontinuallycheckthejoystickdevice andcreatesalistofeventscallr. Foreacheventinthelistitcheckswhetherit wasakeyboardstyleevent. Itthencomparesthethekeycodetothevalues forup,down,leftandrightandpirntsa correspondingmessage
3.
ScrollingMessage fromsense_hatimportSenseHat sense=SenseHat() whileTrue: sense.show_message("Spaaaaaaace!!",scroll_speed=0.05,text_colour=[255,255,0],back_colour=[0,0,255]) EnvironmentalSensing Rotatingletter“J” fromsense_hatimportSenseHat sense=SenseHat() whileTrue: t=sense.get_temperature() p=sense.get_pressure() h=sense.get_humidity() t=round(t,1) p=round(p,1) h=round(h,1) msg="Temp=%s,Pressure=%s, Humidity=%s"%(t,p,h) sense.show_message(msg,scroll_speed=0.05) fromsense_hatimportSenseHat importtime sense=SenseHat() sense.show_letter("J") whileTrue: x,y,z=sense.get_accelerometer_raw().values() x=round(x,0) y=round(y,0) ifx==-1: sense.set_rotation(180) elify==-1: sense.set_rotation(90) elify==1: sense.set_rotation(270) else: sense.set_rotation(0) time.sleep(0.1)
4.
ReactionGame fromsense_hatimportSenseHat importtime importrandom sense=SenseHat() #setupthecolours(white,green,red,empty) w=[150,150,150] g=[0,255,0] r=[255,0,0] e=[0,0,0] #createthreedifferentcolouredarrows arrow=[e,e,e,w,w,e,e,e, e,e,w,w,w,w,e,e, e,w,e,w,w,e,w,e, w,e,e,w,w,e,e,w, e,e,e,w,w,e,e,e, e,e,e,w,w,e,e,e, e,e,e,w,w,e,e,e, e,e,e,w,w,e,e,e] arrow_red=[e,e,e,r,r,e,e,e, e,e,r,r,r,r,e,e, e,r,e,r,r,e,r,e, r,e,e,r,r,e,e,r, e,e,e,r,r,e,e,e, e,e,e,r,r,e,e,e, e,e,e,r,r,e,e,e, e,e,e,r,r,e,e,e] arrow_green=[e,e,e,g,g,e,e,e, e,e,g,g,g,g,e,e, e,g,e,g,g,e,g,e, g,e,e,g,g,e,e,g, e,e,e,g,g,e,e,e, e,e,e,g,g,e,e,e, e,e,e,g,g,e,e,e, e,e,e,g,g,e,e,e] pause=3 score=0 angle=0 play=True sense.show_message("Keepthearrowpointingup",text_colour=[100,100,100]) whileplay==True: last_angle=angle whileangle==last_angle: angle=random.choice([0,90,180,270]) sense.set_rotation(angle) sense.set_pixels(arrow) time.sleep(pause) x,y,z=sense.get_accelerometer_raw().values() x=round(x,0) y=round(y,0) ifx==-1andangle==180: sense.set_pixels(arrow_green) score=score+1 elifx==1andangle==0: sense.set_pixels(arrow_green) score=score+1 elify==-1andangle==90: sense.set_pixels(arrow_green) score=score+1 elify==1andangle==270: sense.set_pixels(arrow_green) score=score+1 else: sense.set_pixels(arrow_red) play=False pause=pause*0.95 time.sleep(0.5) msg="Yourscorewas%s"%(score) sense.show_message(msg,scroll_speed=0.05,text_colour=[100,100,100])
Baixar agora