31.07.2015 Views

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A TEACHER’S GUIDE TO THE INTEL® GALILEO | 42Coding1. Open <strong>the</strong> Arduino IDE. Check that <strong>the</strong> COM port assigned <strong>to</strong> <strong>the</strong> <strong>Intel</strong>® board (go <strong>to</strong>‘Device Manager’ <strong>to</strong> check), matches <strong>the</strong> correct COM port according <strong>the</strong> <strong>the</strong> IDE.2. Check also that <strong>the</strong> correct <strong>Intel</strong>® board has been selected.3. Copy and paste <strong>the</strong> code below, noting value set for pho<strong>to</strong>cell. (You can calibrate <strong>to</strong> yourroom setting using <strong>the</strong> 10K potentiometer.)int ledPin = 11; // LED connected <strong>to</strong> digital pin 11const int analogInPin = 0; // Analog input pin that <strong>the</strong> potentiometer is attached <strong>to</strong>int sensorValue = 0; // value read from <strong>the</strong> potint outputValue = 0;void setup() {pinMode(ledPin, OUTPUT); //Serial.begin(9600);}void loop() {// read <strong>the</strong> analog in value:sensorValue = analogRead(analogInPin);Serial.print("sensor value in is ");Serial.println(sensorValue);// logic for night ligh<strong>to</strong>utputValue = map(sensorValue, 0, 1023, 0, 255);if (outputValue < 102) {analogWrite(ledPin, outputValue);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!