Skip to content

Instantly share code, notes, and snippets.

View boxalljohn's full-sized avatar

John Boxall boxalljohn

View GitHub Profile
if ( temperature > 100 )
{
digitalWrite(13, LOW); // turn off kettle
}
else
{
digitalWrite(13, HIGH); // leave kettle on
}
if ( temperature > 100 )
{
digitalWrite(13, LOW); // turn off kettle
}
else if (humidity > 80 )
{
digitalWrite(7, HIGH); // turn on pin 7
}
// 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
// Example 8.1
int character = 0; // for incoming serial data
void setup()
{
Serial.begin(9600);
}
void loop()
{
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;
// 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);
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)
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, loopy);
digitalWrite(latchpin, HIGH);
// example 5.3
int forward = 12;
int left = 9;
int right = 7;
int del = 5000;
void setup()
{
pinMode(forward, OUTPUT);
// Example 5.4
int forward = 12;
int left = 9;
int right = 7;
int del = 5000;
void setup()
{
pinMode(forward, OUTPUT);