-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmontenegro-AccelerometerColors
43 lines (32 loc) · 2.38 KB
/
montenegro-AccelerometerColors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Using the Accelerometer in MakeCode
For my code, there are two levels.
One level is a basic light sensor, that was used in our dance performance. For this,
the light sensor will detect when the light level is less than 5, meaning that once
the sensor is subject to a specific amount of darkness, then the LEDs on the CPx
will light up in white. This is because the light sensor on the CPx can detect various
levels of light, causing a reaction from the CPx for whatever it is programmed to do.
![alt text](https://102reasonstodcs.files.wordpress.com/2018/03/first.png)
## Second Piece of the Puzzle
For the second part of my code, I have initialized the accelerometer to use the x axis
of the CPx’s orientation. I have also set the limit for the accelerometer on the x axis
to 1023, which means that for each movement along the x axis (horizontally), the CPx will illuminate
an LED in a different color along the rainbow spectrum up to the color that sits at
the value of 1023 (red). The last part of this code is the console log value, which basically
will associate all values of the x axis to the sensor reading, which will in turn, allow the CPx
to interpret the meanings of the accelerometer, thus translating the readings into the
colors seen on the CPx. This means that with the light level, the above code will only
initialize when the light sensors detect darkness.
![Alt](https://102reasonstodcs.files.wordpress.com/2018/03/second.png)
## Third Piece of the Puzzle
For the third part of my code, I have replaced the general ‘while’ statement
with an ‘if, else’ statement, which uses the light level specifications as the if
statement, causing the accelerometer code to initiate when the light level is
less than 5. A "while" statement will cause the code to work only while a certain
condition is met. An "if" statement will cause the code to work only if a
specific condition is met. These are usually accompanied by an 'else' portion which
will work if the 'if' statement is not met; this will work for every piece of code that
does not meet the prior 'if' statement. So for the code, if the light level is greater
than 5, then the code states that the pixels on the CPx will illuminate red.
![Alt](https://102reasonstodcs.files.wordpress.com/2018/03/third.png)
View my video
[![Here](https://img.youtube.com/vi/Goys7Cale_A/0.jpg)](https://www.youtube.com/watch?v=Goys7Cale_A).