O'Reilly logo

LEGO und Elektronik - Raspberry Pi, Arduino, Sensoren, Motoren und vieles mehr einsetzen und programmieren by Thomas Kaffka

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Anhang

A.1  Codeschnipsel zu den einzelnen Komponenten

A.1.1  Licht-Sensor

für den Raspberry Pi:

ptrans = PhotoTransistor(0, 3, 16, 5, 12)
value = ptrans.readValue()

für den Arduino:

PhotoTransistor tran(0);
int value = tran.readValue();

A.1.2  Infrarot-Sensor

für den Raspberry Pi:

irsensor = InfraredSensor(0, 3, 16, 5, 12)
value = irsensor.readValue()

für den Arduino:

InfraredSensor ir(0);
int value = ir.distance();

A.1.3  Ultraschall-Sensor

für den Raspberry Pi:

ussensor = UltrasonicSensor(29, 7)
value = ussensor.distance()

für den Arduino:

UltrasonicSensor us(12, 11);
int value = us.ranging();

A.1.4  Touch-Sensor

für den Raspberry Pi:

touch = TouchSensor(40)
if (touch.isTouch()):
   pass

für den Arduino: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required