updated glowing pendulum
This commit is contained in:
		@@ -15,8 +15,6 @@ basic.forever(() => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value.
 | 
					Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value.
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```blocks
 | 
					```blocks
 | 
				
			||||||
basic.forever(() => {
 | 
					basic.forever(() => {
 | 
				
			||||||
    let acceleration = input.acceleration(Dimension.Y);
 | 
					    let acceleration = input.acceleration(Dimension.Y);
 | 
				
			||||||
@@ -25,7 +23,6 @@ basic.forever(() => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Since the micro:bit will be swinging back and forth, the acceleration will only be positive half of the time. Thus, to always get a positive value, we want to take the absolute value of the acceleration.
 | 
					Since the micro:bit will be swinging back and forth, the acceleration will only be positive half of the time. Thus, to always get a positive value, we want to take the absolute value of the acceleration.
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
```blocks
 | 
					```blocks
 | 
				
			||||||
let acceleration = 0;
 | 
					let acceleration = 0;
 | 
				
			||||||
@@ -37,15 +34,50 @@ basic.forever(() => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
The function `acceleration(y)` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `set brightness()` only accepts a value between 0 and 256. Thus, we need to divide the acceleration by 4 to ensure we will be in the appropriate range.
 | 
					The function `acceleration(y)` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `set brightness()` only accepts a value between 0 and 256. Thus, we need to divide the acceleration by 4 to ensure we will be in the appropriate range.
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					```blocks
 | 
				
			||||||
 | 
					basic.forever(() => {
 | 
				
			||||||
 | 
					    let acceleration = input.acceleration(Dimension.Y);
 | 
				
			||||||
 | 
					    acceleration = Math.abs(acceleration);
 | 
				
			||||||
 | 
					    acceleration = acceleration / 4;
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Now let's use our acceleration value to set the brightness on the micro:bit.
 | 
					Now let's use our acceleration value to set the brightness on the micro:bit.
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					```blocks
 | 
				
			||||||
 | 
					basic.forever(() => {
 | 
				
			||||||
 | 
					    let acceleration = input.acceleration(Dimension.Y);
 | 
				
			||||||
 | 
					    acceleration = Math.abs(acceleration);
 | 
				
			||||||
 | 
					    acceleration = acceleration / 4;
 | 
				
			||||||
 | 
					    led.setBrightness(acceleration)
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Let's show what the brightness of the micro:bit is by turning all the LEDs on!
 | 
					Let's show what the brightness of the micro:bit is by turning all the LEDs on!
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					```blocks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					basic.forever(() => {
 | 
				
			||||||
 | 
					    let acceleration = input.acceleration(Dimension.Y);
 | 
				
			||||||
 | 
					    acceleration = Math.abs(acceleration);
 | 
				
			||||||
 | 
					    acceleration = acceleration / 4;
 | 
				
			||||||
 | 
					    led.setBrightness(acceleration)
 | 
				
			||||||
 | 
					    basic.showLeds(`
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        `)
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### ~avatar avatar
 | 
					### ~avatar avatar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,23 @@ Coding challenges for the glowing pendulum tutorial.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Complete the following [glowing pendulum activity](/lessons/glowing-pendulum/activity) and your code should look like this:
 | 
					Complete the following [glowing pendulum activity](/lessons/glowing-pendulum/activity) and your code should look like this:
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					```blocks
 | 
				
			||||||
 | 
					basic.forever(() => {
 | 
				
			||||||
 | 
					    let acceleration = input.acceleration(Dimension.Y);
 | 
				
			||||||
 | 
					    acceleration = Math.abs(acceleration);
 | 
				
			||||||
 | 
					    acceleration = acceleration / 4;
 | 
				
			||||||
 | 
					    led.setBrightness(acceleration)
 | 
				
			||||||
 | 
					    basic.showLeds(`
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        # # # # #
 | 
				
			||||||
 | 
					        `)
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**Challenge 1**
 | 
					**Challenge 1**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user