Question

In: Computer Science

Write a program for Sense HAT (or the emulator) to map X, Y, and Z acceleration...

Write a program for Sense HAT (or the emulator) to map X, Y, and Z acceleration (or orientation) values into R, G, and B color values on the LED matrix. That way, when you tilt the Sense HAT, the LED matrix will display different colors to simulate a paint mixer.
When you write your program, please consider using delay to avoid the problem of changing color too fast to be perceived. Also, you want to make sure that you map the X, Y, and Z values appropriately to prevent the problem of color values changing very little.

Solutions

Expert Solution

Answer : Given data

Program for Sense HAT is

#Python implementation of SenseHat

from sense_hat import SenseHat

sense = SenseHat()

#set the values of the colors

red = (255, 0, 0)

green = (0, 255, 0)

blue = (0, 0, 255)

while True:

#acceleration for each axis (x, y, and z) is extracted and rounded off to nearest integer

acceleration = sense.get_accelerometer_raw()

x = acceleration['x']

y = acceleration['y']

z = acceleration['z']

x=round(x, 0)

y=round(y, 0)

z=round(z, 0)

print("x={0}, y={1}, z={2}".format(x, y, z))

# example using format (x, y,z, pixel)

sense.set_pixel(1, 0,0, red)

sense.set_pixel(0, 1, 0,green)

sense.set_pixel(0, 0,1, blue)

Snippet of code is attached below:

from sense_hat import SenseHat

sense = SenseHat()

#set the values of the colors

red = (255, 0, 0)

green = (0, 255, 0)

blue = (0, 0, 255)

while True:

#acceleration for each axis (x, y, and z) is extracted and rounded off to nearest integer

     acceleration = sense.get_accelerometer_raw() 

     x = acceleration['x']

     y = acceleration['y']

     z = acceleration['z']

     x=round(x, 0)

     y=round(y, 0)

     z=round(z, 0)

     print("x={0}, y={1}, z={2}".format(x, y, z)) 

# example using format (x, y,z, pixel)

sense.set_pixel(1, 0,0, red)

sense.set_pixel(0, 1, 0,green)

sense.set_pixel(0, 0,1, blue)
                    _____________THE END_______________

Related Solutions

Python # Write a program that examines three variables—x, y, and z # and prints the...
Python # Write a program that examines three variables—x, y, and z # and prints the largest odd number among them. # If none of them are odd, it should print a message to that effect. n = input('Enter the 1st Integer x: ') x = int(n) n = input('Enter the 2nd Integer y: ') y = int(n) n = input('Enter the 3rd Integer z: ') z = int(n) if x % 2 == 0 and y % 2 ==...
The curried version of let f (x,y,z) = (x,(y,z)) is let f (x,(y,z)) = (x,(y,z)) Just...
The curried version of let f (x,y,z) = (x,(y,z)) is let f (x,(y,z)) = (x,(y,z)) Just f (because f is already curried) let f x y z = (x,(y,z)) let f x y z = x (y z)
Let X, Y ⊂ Z and x, y ∈ Z Let A = (X\{x}) ∪ {x}....
Let X, Y ⊂ Z and x, y ∈ Z Let A = (X\{x}) ∪ {x}. a) Prove or disprove: A ⊆ X b) Prove or disprove: X ⊆ A c) Prove or disprove: P(X ∪ Y ) ⊆ P(X) ∪ P(Y ) ∪ P(X ∩ Y ) d) Prove or disprove: P(X) ∪ P(Y ) ∪ P(X ∩ Y ) ⊆ P(X ∪ Y )
If X, Y and Z are three arbitrary vectors, prove these identities: a. (X×Y).Z = X.(Y×Z)...
If X, Y and Z are three arbitrary vectors, prove these identities: a. (X×Y).Z = X.(Y×Z) b. X×(Y×Z) = (X.Z)Y – (X.Y)Z c. X.(Y×Z) = -Y.(X×Z)
Digital Logic Simplify: F = (x’∙ y’∙ z’) + (x’∙ y ∙ z’) + (x ∙...
Digital Logic Simplify: F = (x’∙ y’∙ z’) + (x’∙ y ∙ z’) + (x ∙ y’ ∙ z’) + (x ∙ y ∙ z) F = (x + y + z’) (x + y’ + z’) (x’ + y + z’) (x’ + y’ + z)
Use two different ways to prove X Y + Z = (X + Z)(Y + Z)....
Use two different ways to prove X Y + Z = (X + Z)(Y + Z). a) Use pure algebraic way b) k-maps
For each of the formulas below, state whether it is true or false. a) pX,Y,Z(x,y,z)=pY(y)pZ∣Y(z∣y)pX∣Y,Z(x∣y,z)   ...
For each of the formulas below, state whether it is true or false. a) pX,Y,Z(x,y,z)=pY(y)pZ∣Y(z∣y)pX∣Y,Z(x∣y,z)       Select an option         True         False    b) pX,Y∣Z(x,y∣z)=pX(x)pY∣Z(y∣z)       Select an option         True         False    c) pX,Y∣Z(x,y∣z)=pX∣Z(x∣z)pY∣X,Z(y∣x,z)       Select an option         True         False    d) ∑xpX,Y∣Z(x,y∣z)=1       Select an option         True         False    e) ∑x∑ypX,Y∣Z(x,y∣z)=1       Select an option         True   ...
Find ??, ?? and ?? of F(x, y, z) = tan(x+y) + tan(y+z) – 1
Find ??, ?? and ?? of F(x, y, z) = tan(x+y) + tan(y+z) – 1
Given function f(x,y,z)=x^(2)+2*y^(2)+z^(2), subject to two constraints x+y+z=6 and x-2*y+z=0. find the extreme value of f(x,y,z)...
Given function f(x,y,z)=x^(2)+2*y^(2)+z^(2), subject to two constraints x+y+z=6 and x-2*y+z=0. find the extreme value of f(x,y,z) and determine whether it is maximum of minimum.
*(1)(a) Find a formula for the intersection of a cone {(x,y,z): x^2+y^2=z^2} with a plane {(x,y,z):...
*(1)(a) Find a formula for the intersection of a cone {(x,y,z): x^2+y^2=z^2} with a plane {(x,y,z): z=c}. (b) Find a formula for the intersection of a cone {(x,y,z): x^2+y^2=z^2} with a plane {(x,y,z): x=a}. (c) Find a formula for the intersection of a cone {(x,y,z): x^2+y^2=z^2} with a plane {(x,y,z): y=b}. *(2) Find a formula for the intersection of a cone {(x,y,z): x^2+y^2=z^2} with a plane {(x,y,z): z=kx+b} assuming both b and k are positive. (a) For what value of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT