This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ( temperature > 100 ) | |
| { | |
| digitalWrite(13, LOW); // turn off kettle | |
| } | |
| else | |
| { | |
| digitalWrite(13, HIGH); // leave kettle on | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ( temperature > 100 ) | |
| { | |
| digitalWrite(13, LOW); // turn off kettle | |
| } | |
| else if (humidity > 80 ) | |
| { | |
| digitalWrite(7, HIGH); // turn on pin 7 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Exercise 0.1 | |
| // The setup() method runs once, when the sketch starts | |
| int del=100; // sets a default delay time, 100 milliseconds (one tenth of a second) | |
| void setup() | |
| { | |
| // initialize the digital pins as outputs: | |
| // later on there will be easier ways to do this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example 8.1 | |
| int character = 0; // for incoming serial data | |
| void setup() | |
| { | |
| Serial.begin(9600); | |
| } | |
| void loop() | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| switch (zz) { | |
| case 10: | |
| //do something when variable zz equals 10 | |
| break; | |
| case 20: | |
| //do something when variable zz equals 20 | |
| break; | |
| case 30: | |
| // do something when variable equals 30 | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // DS1307/3232 SQW generator | |
| #include "Wire.h" | |
| #define DS1307_I2C_ADDRESS 0x68 // each I2C object has a unique bus address, the DS1307 is 0x68 | |
| void setup() | |
| { | |
| Wire.begin(); | |
| } | |
| void sqw1() // set to 1Hz | |
| { | |
| Wire.beginTransmission(DS1307_I2C_ADDRESS); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void displaynumber(int rawnumber, int cycles) | |
| // takes an integer and displays it on our 4-digit LED display module and HOLDS it on the display for 'cycles' number of cycles | |
| { | |
| for (int q=1; q<=cycles; q++) | |
| { | |
| if (rawnumber>=0 && rawnumber<10) | |
| { | |
| onedigitnumber(rawnumber); | |
| } | |
| else if (rawnumber>=10 && rawnumber<100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| digitalWrite(latchpin, LOW); | |
| shiftOut(datapin, clockpin, MSBFIRST, loopy); | |
| digitalWrite(latchpin, HIGH); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // example 5.3 | |
| int forward = 12; | |
| int left = 9; | |
| int right = 7; | |
| int del = 5000; | |
| void setup() | |
| { | |
| pinMode(forward, OUTPUT); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example 5.4 | |
| int forward = 12; | |
| int left = 9; | |
| int right = 7; | |
| int del = 5000; | |
| void setup() | |
| { | |
| pinMode(forward, OUTPUT); |