This file contains 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 setup() | |
{ | |
// Initialise my serial port with 9600 baud | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
// Wait a second | |
delay(1000); |
This file contains 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 setup() | |
{ | |
// Initialise my serial port with 9600 baud | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
// Analog values are read as integer values between 1 and 1023. | |
// Each 1 is a fraction of 5V. So 0 = 0V, 1023 = 5V, and the scale |
This file contains 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
const int SPEEDPIN = 2; | |
// Sample every 500ms | |
const int SAMPLEFREQ = 500; | |
// Variables for storing state. | |
int switchState = 0; | |
int lastSwitchState = 0; | |
// Variable for remembering when we last sampled. |
This file contains 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
(string value1, string value2) SomeFunc() | |
{ | |
return ("val1", "val2"); | |
} | |
void CallerFunction() | |
{ | |
var result = SomeFunc(); | |
Console.WriteLine(result.value1); // val1 |
This file contains 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
(string value1, string value2) SomeFunc() | |
{ | |
return ("val1", "val2"); | |
} | |
void CallerFunction() | |
{ | |
var result = SomeFunc(); | |
Console.WriteLine(result.value1); // val1 |
This file contains 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 SomeMethod(List<KeyValuePair<string, string>> pairs) | |
{ | |
// Use the values | |
} | |
void Caller() { | |
// Yuck! | |
SomeMethod(new List<KeyValuePair<string, string>> |
This file contains 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
// Forgive me for this function name | |
KeyValuePair<string, string> KVP(string key, string val) | |
{ | |
return new KeyValuePair<string, string>(key, val); | |
} | |
void Caller() | |
{ | |
// Still pretty bad | |
SomeMethod(new List<KeyValuePair<string, string>> { |
This file contains 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 SomeMethod(KeyValuePair<string, string>[] pairs) | |
{ | |
} | |
void Caller() | |
{ | |
// Ok, so I hate myself a little less | |
SomeMethod(new[] | |
{ | |
KVP("key1", "val1"), |
This file contains 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 SomeMethod(params KeyValuePair<string, string>[] pairs) | |
{ | |
} | |
void Caller() | |
{ | |
// params are great, but I still don't love it. | |
SomeMethod( | |
KVP("key1", "val1"), | |
KVP("key2", "val2") |
This file contains 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 SomeMethod(params (string key, string value)[] pairs) | |
{ | |
} | |
void Caller() | |
{ | |
// Now that's more like it! | |
SomeMethod( | |
("key1", "val1"), | |
("key2", "val2") |