Skip to content

Commit

Permalink
Merge pull request #24 from CleoQc/master
Browse files Browse the repository at this point in the history
Fix Light Follower block; change icon
  • Loading branch information
CleoQc authored Oct 9, 2018
2 parents 5dab43b + 11f3f18 commit 73c7447
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ gigglebot.spinMillisec(gigglebotWhichTurnDirection.Left, 1000)
```

#### Steering is up to you, you can use it to orbit around a "sun". #steerMillisec
With steering you control how much turning each wheel can do. In this example, the robot will halfway to the right, doing a curve around an object. The first number is percent-based. With a value of 0, the robot will not turn at all. With a value of 100, you will get the same behavior as the turn block.
With steering you control how much turning each wheel can do. In this example, the robot will turn halfway to the right, doing a curve around an object. The first number is percent-based. With a value of 0, the robot will not turn at all. With a value of 100, you will get the same behavior as the turn block.
```blocks
gigglebot.steerMillisec(50, gigglebotWhichTurnDirection.Right, 1000)
```
Expand Down Expand Up @@ -94,10 +94,13 @@ basic.forever(() => {

### Following a light #lightfollow

The GiggleBot comes with two light sensors that allows it to follow a spotlight, a little bit like a cat would. Shining a flashlight onto one eye will get the GiggleBot to turn in that direction.
The GiggleBot comes with two light sensors that allows it to follow a spotlight, a little bit like a cat would. Shining a flashlight onto one eye will get the GiggleBot to turn in that direction. You need to put this block in a loop. You may use a forever loop or one where you control the end condition. Make sure you stop the robot when exiting the loop!
```blocks
input.onButtonPressed(Button.A, () => {
gigglebot.lightFollow()
while (!(input.buttonIsPressed(Button.B))) {
gigglebot.lightFollow()
}
gigglebot.stop()
})
```

Expand Down
33 changes: 25 additions & 8 deletions gigglebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,36 @@ namespace gigglebot {
//% group=LightSensors
//% weight=40
export function lightFollow() {
let diff = 0
let current_lights = lightSensorsRaw()
diff = Math.abs((current_lights[0] - current_lights[1])) / 10;
if (current_lights[0] > current_lights[1]) {
// it's brighter to the right
motorPowerAssignBoth(motorPowerLeft, motorPowerRight - diff)
let diff = 20
let current_lights = gigglebot.lightSensorsRaw()
// serial.writeNumbers(current_lights)
if (current_lights[0] < 10 && current_lights[1] < 10) {
}
else {
else if (current_lights[0] > current_lights[1] + diff) {
// it's brighter to the right
// lights.smileShow(NeoPixelColors.Black)
// lights.whichEye(gigglebotWhichEye.Right).setPixelColor(0, neopixel.colors(NeoPixelColors.Yellow))
// lights.whichEye(gigglebotWhichEye.Left).setPixelColor(0, neopixel.colors(NeoPixelColors.Black))
// lights.whichEye(gigglebotWhichEye.Both).show()
gigglebot.turn(gigglebotWhichTurnDirection.Right)
} else if (current_lights[1] > current_lights[0] + diff) {
// it's brighter to the left
motorPowerAssignBoth(motorPowerLeft - diff, motorPowerRight)
// lights.smileShow(NeoPixelColors.Black)
// lights.whichEye(gigglebotWhichEye.Left).setPixelColor(0, neopixel.colors(NeoPixelColors.Yellow))
// lights.whichEye(gigglebotWhichEye.Right).setPixelColor(0, neopixel.colors(NeoPixelColors.Black))
// lights.whichEye(gigglebotWhichEye.Both).show()
gigglebot.turn(gigglebotWhichTurnDirection.Left)
} else {
// lights.whichEye(gigglebotWhichEye.Left).setPixelColor(0, neopixel.colors(NeoPixelColors.Violet))
// lights.whichEye(gigglebotWhichEye.Right).setPixelColor(0, neopixel.colors(NeoPixelColors.Violet))
// lights.whichEye(gigglebotWhichEye.Both).show()
// lights.smileRainbow()
gigglebot.driveStraight(gigglebotWhichDriveDirection.Forward)
}
basic.pause(100)
}


/**
* Reads left or right light sensor.
* The light sensors are placed in front of each eye neopixel, they're tiny!
Expand Down
Binary file added icon2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gigglebot",
"version": "1.0.4",
"version": "1.0.5",
"dependencies": {
"core": "*",
"distanceSensor": "github:dexterind/pxt-distancesensor#v0.0.1"
Expand Down

0 comments on commit 73c7447

Please sign in to comment.