Write the code to display a smiling face

Assignment Help Computer Engineering
Reference no: EM133577545

LAB: Familiar with a Sense Hat

Overview:
In this lab, you will learn how to control the LEDs, display an image, character, message in the sense hat; monitor the temperature, pressure, and humidity; play with the joystick.

Exercise 1: Controlling LEDs
Control the color in a specific LED on Sense Hat. Run the following sample code that sets LED in row 1 and column 1 to red.

from sense_hat import SenseHat       
sense = SenseHat()    # create a sense hat object       
sense.clear() # clear all LEDs red = (255, 0, 0)
sense.set_pixel(1, 1, red)

You should also try to set LED to different colors, such as green = (0,255,0) and blue=(0,0,255).

Question 1: Please write the code to draw a green diagonal line.

Exercise 2: Displaying an Image

Run the following code that displays a "smiling" face using LEDs.

from sense_hat import SenseHat       
sense = SenseHat()       
sense.clear()       
e = (0, 0, 0)       
w = (255, 255, 255)       
image = [       
e,e,w,w,w,w,e,e,       
e,w,e,e,e,e,w,e,       
w,e,w,e,e,w,e,w,       
w,e,e,e,e,e,e,w,       
w,e,w,e,e,w,e,w,       
w,e,e,w,w,e,e,w,       
e,w,e,e,e,e,w,e,       
e,e,w,w,w,w,e,e    

]
sense.set_pixels(image)

Question 2: Please write the code to display a "smiling" face when you are happy and "sad" face when you are sad.

Exercise 3: Displaying a Single Character

Run the following sample code that displays the letter "%" with red color.Run the following sample code that displays the letter "%" with red color.

from sense_hat import SenseHat
sense = SenseHat()
red = (255, 0, 0)
sense.show_letter("%", red)

You can also display any single digit (e.g., 5) using the same method.

Question 3: Please write the code to repeatedly display letters "E", "L" and "E" every 1 second.

Hint: you may want to use the sleep() function from the Python time module. For example, the following code shows that the program stops for one second.

from time import sleep       
sleep(1)

Exercise 4: Displaying a MessageRun the following sample code that displays a message "ELE" with rolling speed of 0.1.

from sense_hat import SenseHat       
sense = SenseHat()       
blue = (0, 0, 255)       
yellow = (255, 255, 0)       
while True:       
sense.show_message("ELE", text_colour=yellow,
back_colour=blue, scroll_speed=0.1)

Question 4: Please write the code to display the message "ELE 409" with "blue" text color and empty background color.

Exercise 5: Sensing the EnvironmentRun the following sample code that measures the pressure, temperature, and humidity.

from sense_hat import SenseHat       
sense = SenseHat()    
 
while True:       
t = round(sense.get_temperature(),1) p = round(sense.get_pressure()/10,1)
h  =  round(sense.get_humidity(),1)       
temp = "Temperature: " + str(t) + " C" + "\n" pres = "Pressure: " + str(p) + " kPa" + "\n"
humi = "Pressure: " + str(h) + " %"       
message = temp + pres + humi print(message)
sleep(2)

Question 5: Please write the code to display temperature on Sense Hat and change the background color to "green" when the temperature is between 22 and 27 celsius, "red" when it is above 27 celsius, and "blue" when it is under 22 celsius.

Note: Due to the Sense Hat being close to the Raspberry Pi's CPU, it's temperature gradually increases.

Exercise 6: Playing with the Joystick

Run the following sample code that controls one LED light using the joystick.

from sense_hat import SenseHat       

sense = SenseHat() sense.clear()
R = (255,0,0)
x = 3
y = 3 sense.set_pixel(x,y,R)

while True:
for event in sense.stick.get_events(): if event.action == "pressed":
if event.direction == "up" and y > 0: sense.clear()
y = y - 1

Question 6: Please write the code to implement the following additional function:

The LED light can freely move around the 2D space;

When the LED light touches the boundary, it first reaches the boundary, lasts for 1 second, disappears, and resets to initial position (3,3).
Bonus Question (1 point on the final grade for both ELE 408 and ELE 409): Please write the code to implement the Snake Game and use the joystick to control the snake. You have two weeks to complete this task.

Reference no: EM133577545

Questions Cloud

How do you think financial institutions : What skills do you think are needed to be a successful investigator? How do you think financial institutions should address challenges investigators encounter?
Professional and accountable police department : Describe a good professional and accountable police department (PATS). The law enforcement profession is good at training new recruits.
Difference between sexual deviance and sex crime : What is the difference between sexual deviance and a sex crime? What do we know about child sex abuse? What do we know about sex offenders?
Discuss how a person may be found not guilty in criminal : Discuss how a person may be found not guilty in criminal court, but liable in civil court.
Write the code to display a smiling face : Write the code to display a smiling face when you are happy and "sad" face when you are sad.
Emergency management principles : Describe 2 recent disasters and how you see emergency management principles being applied to them.
Discuss recent statutory intervention in queensland : What are some examples of the different approaches taken by judges to human rights in the statutory interpretation process. Also, discuss recent statutory
Norman knocks her down during argument : Hazel's arm is broken when Norman knocks her down during an argument. Since this can be both a criminal or civil matter,
Describe the path this case took to reach the supreme court : Explain the dispute in the case. Describe the path this case took to reach the Supreme Court. Summarize the arguments made by the lawyers for both sides in this

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd