Last active
August 29, 2015 14:24
-
-
Save stonehippo/73c9a4cd84f575a3e128 to your computer and use it in GitHub Desktop.
Spark: Intro to Arduino
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 setup() { | |
// This code is run once, each time the Arduino is powered on or reset | |
} | |
void loop() { | |
// This code is run repeatedly, as fast as the Arduino can run it | |
} |
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
const int LED = 13; // Use the built-in LED on digital pin 13 | |
void setup() { | |
pinMode(LED, OUTPUT); // set the digital GPIO to control state | |
} | |
void loop() { | |
digitalWrite(LED, HIGH); // turn the LED on | |
delay(250); // wait 1/4 second | |
digitalWrite(LED, LOW); // turn the LED off | |
delay(250); // wait another 1/4 second | |
} |
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
const int LED = 13; | |
const int BUTTON = 5; // use a momentary switch | |
void setup() { | |
pinMode(LED, OUTPUT); | |
pinMode(BUTTON, INPUT_PULLUP); | |
} | |
void loop() { | |
if (digitalRead(BUTTON) == LOW) { | |
digitalWrite(LED, HIGH); | |
delay(250); | |
digitalWrite(LED, LOW); | |
delay(250); | |
} | |
} |
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
// For this example, I'm using an FSR, but just about any simple analog sensor would work | |
const int SENSOR_PIN = A0; | |
int fsrReading = 0; | |
void setup() { | |
Serial.begin(9600); // fire up Serial so we can output values to the console | |
} | |
void loop() { | |
// Read the state of the analog pin, and get back a value in the range 0-1024 | |
fsrReading = analogRead(SENSOR_PIN); | |
// Display the value we read on the Serial console | |
Serial.print("The current reading from the FSR is: "); | |
Serial.println(fsrReading); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment