Skip to content

Instantly share code, notes, and snippets.

View gallaugher's full-sized avatar

Gallaugher gallaugher

View GitHub Profile
@gallaugher
gallaugher / Arduino_SOS
Created June 4, 2018 23:19
SOS blink lon pin 8
#define LED 8
#define dot_duration 250
#define dash_duration dot_duration * 3
#define pause_duration dot_duration
#define letter_pause dot_duration * 3
#define word_pause dot_duration * 7
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
@gallaugher
gallaugher / gist:5d19fbc190f35814c3e3ea30cbccb5e9
Last active June 5, 2018 21:12
Txplore Arduino LBD Day 4, Example 1 - ten random numbers, even or odd
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// put this here so that each time I restart with button press I have a line feed gap so I can easily compare with prior results
Serial.println();
randomSeed(analogRead(0)); // supposed to make sure random simulates (pseudo random) a random number.
// uncomment for mini project 1
ten_random_numbers();
@gallaugher
gallaugher / gist:a31e4b59cb4f957fff5f05992bd4e375
Last active June 6, 2018 01:05
Day 12, Learning By Doing 5
byte BUTTON_PIN = 7;
byte LED_PIN = 6;
byte buttonState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
@gallaugher
gallaugher / TXplore LBD 5 Bonus - while
Created June 6, 2018 01:13
Day 12, Learning By Doing 5 - BONUS while
byte BUTTON_PIN = 7;
byte LED_PIN = 6;
byte buttonState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
@gallaugher
gallaugher / gist:9894fdfb826fece2e034767f9aedb8e0
Created June 6, 2018 01:20
TXPlore Day 12, Learning By Doing 5 - BONUS Switch Case
byte BUTTON_PIN = 7;
byte LED_PIN = 6;
byte buttonState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
@gallaugher
gallaugher / Day 12, Learning By Doing 5 - mini project 2 - persistent button press
Created June 6, 2018 01:58
TXPlore Day 12, Learning By Doing 5 - mini project 2 - persistent button press
byte BUTTON_PIN = 7;
byte LED_PIN = 6;
bool newState = LOW;
bool currentState = LOW;
void setup() {
// put your setup code here, to run once:
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
@gallaugher
gallaugher / Convenience Initializers for Spot.swift
Last active June 8, 2018 23:48
Spot.swift convenience initializers
init(name: String, address: String, coordinate: CLLocationCoordinate2D, averageRating: Double, numberOfReviews: Int, postingUserID: String, documentID: String) {
self.name = name
self.address = address
self.coordinate = coordinate
self.averageRating = averageRating
self.numberOfReviews = numberOfReviews
self.postingUserID = postingUserID
self.documentID = documentID
}
@gallaugher
gallaugher / Sort and SortBy.swift
Created June 9, 2018 16:50
Swift .sort(by:) and .sorted(by:) examples
var favoriteFoods = ["Pizza", "Apple Pie", "Sushi", "Bacon"]
let aToZFoods = favoriteFoods.sorted()
print(aToZFoods) // sorted array
print(favoriteFoods) // unchanged original
print("")
// .sorted() is the same as .sorted(by: <)
let alphabetizedFoods = favoriteFoods.sorted(by: <)
print(alphabetizedFoods) // sorted array
@gallaugher
gallaugher / sorting an array of structs on a single property.swift
Created June 9, 2018 17:47
Sorting an array of structs on a single property
struct City {
var name: String
var rainyDays: Int
var rainTotal: Double
}
var cities: [City] = []
cities.append(City(name: "Seattle", rainyDays: 149, rainTotal: 37.7))
cities.append(City(name: "Phoenix", rainyDays: 30, rainTotal: 8.2))
cities.append(City(name: "Chicago", rainyDays: 124, rainTotal: 36.9))
cities.append(City(name: "Boston", rainyDays: 126, rainTotal: 43.8))
@gallaugher
gallaugher / LBD6.ino
Created June 10, 2018 00:03
Gallaugher - LBD Day 6
void setup() {
// put your setup code here, to run once:
pinMode(7, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// analogRead has possible values from 0...1023
int potValue = analogRead(A0);