32. LED
function () use ($board) {
$led = new CaricaChipLed($board, 9);
$led->blink();
}
33. RGB LED
function () use ($board) {
$colors = array('#F00', '#0F0', '#00F');
$led = new CaricaChipLedRgb($board, 10, 11, 9);
$led->setColor('#000');
$index = 0;
$next = function() use ($led, $colors, &$index, &$next) {
if (isset($colors[$index])) {
$color = $colors[$index];
$led->fadeTo($color)->done($next);
}
if (++$index >= count($colors)) {
$index = 0;
}
};
$next();
}
34. Servo
function () use ($board, $loop) {
$positions = array(
0, 45, 90, 180
);
$servo = new CaricaChipServo($board, 7, -180);
$index = 0;
$loop->setInterval(
$next = function () use ($servo, $positions, &$index) {
if (isset($positions[$index])) {
$position = $positions[$index];
$servo->moveTo($position);
echo $position, " Grad , ", $servo->getPosition(), " Gradn";
}
if (++$index >= count($positions)) {
$index = 0;
}
},
2000
);
$next();
}
35. Analog Sensor
function () use ($board) {
$sensor = new CaricaChipSensorAnalog($board, 14);
$sensor->onChange(
function ($sensor) {
echo $sensor, "n";
}
);
}