Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encourage to use sensor.scaleTo instead Fn.map #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions exercises/robot_arm/problem.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ Utilise un potentiomètre (potard) pour controller la position d'un servomoteur.
## Documentation

- Sensor - https://github.com/rwaldron/johnny-five/wiki/Sensor
- Fn - https://github.com/rwaldron/johnny-five/blob/master/lib/fn.js

## Conseils

- Un potard est un autre cas d'utilisation de l'objet 'Sensor'...
- Un potard a produit des valeurs dans une plage allant de 0 a 1023.
- Un servomoteur peut généralement étre orienté dans un angle de 0 a 180°.
- `five.Fn.map` peut étre utiliser pour normaliser les valeur du potard (0 - 1023) en angles pour le servomoteur (0 - 179).

* * *
* * *
2 changes: 0 additions & 2 deletions exercises/robot_arm/problem.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ GND o---.------/\/\/------.
## ドキュメント

- Sensor - https://github.com/rwaldron/johnny-five/wiki/Sensor
- Fn - https://github.com/rwaldron/johnny-five/blob/master/lib/fn.js

## ヒント

- ポテンショメータは、センサーオブジェクトの別のユースケースです。
- 0〜1023の間の入力値を生成します。
- サーボは通常0〜179度の角度を動くことができます。
- `five.Fn.mapメソッド`はポテンショメータの値(0~1023)をサーボの角度(0~179)にマッピングすることができます。

---
2 changes: 0 additions & 2 deletions exercises/robot_arm/problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ GND o---.------/\/\/------.
## Docs

- Sensor - https://github.com/rwaldron/johnny-five/wiki/Sensor
- Fn - https://github.com/rwaldron/johnny-five/blob/master/lib/fn.js

## Hints

- A potentiometer is another use case for the Sensor object...
- A pot produces input values between 0 and 1023.
- A servo can typically be moved between 0 and 179 degrees.
- `five.Fn.map` can map the pot values (0 - 1023) to servo angles (0 - 179).

---
16 changes: 1 addition & 15 deletions exercises/robot_arm/solution/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@ board.on('ready', function () {
var servo = new five.Servo(9)
var pot = new five.Sensor('A2')

pot.on('change', function () {
var position = five.Fn.map(this.value,
0, 1023,
0, 179
)

servo.to(position)
})

// Alternatively, sensor provides a `scale` method as an alias to Fn.map
/*
pot.scale(0, 179).on('change', function () {

// `this.value` will reflect a scaling from 0-1023 to 0-179
pot.scaleTo(0,179).on('change', function () {
servo.to(this.value)
})
*/
})