Difference between revisions of "Arduino 101"
Jump to navigation
Jump to search
(13 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | = Project 1 = | + | = Presentation = |
− | < | + | |
+ | === Arduino Quick Start === | ||
+ | https://docs.google.com/presentation/d/1PG9YJP-CJ0dU62r9KHZu6RrYr6oOIKasvj2brW6CuD8/edit?usp=sharing | ||
+ | |||
+ | === Arduino 101 === | ||
+ | https://docs.google.com/presentation/d/1sB8RygR-oZyq8jZwiidcsYhblC1duVVDcdwAD0Z3vJI/edit?usp=sharing | ||
+ | |||
+ | = Arduino 101 Projects = | ||
+ | == Project 1 == | ||
+ | <pre> | ||
int potInputPin = 0; | int potInputPin = 0; | ||
int servoOutputPin = 11; | int servoOutputPin = 11; | ||
Line 41: | Line 50: | ||
delay(100); | delay(100); | ||
} | } | ||
− | </ | + | </pre> |
+ | == Project 2 == | ||
+ | <pre> | ||
+ | #include <SPI.h> | ||
+ | #include <SD.h> | ||
+ | |||
+ | int recordingButtonInputPin = 5; | ||
+ | int recordingLEDPin = 2; | ||
+ | boolean isRecording = false; | ||
+ | |||
+ | int ldrInputPin = 1; | ||
+ | |||
+ | int sdChipSelectPin = 7; | ||
+ | |||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | pinMode(recordingButtonInputPin, INPUT); | ||
+ | |||
+ | Serial.begin(9600); | ||
+ | while (!Serial) { | ||
+ | ; // wait for serial port to connect. Needed for native USB port only | ||
+ | } | ||
+ | Serial.print("Initializing SD card..."); | ||
+ | |||
+ | // see if the card is present and can be initialized: | ||
+ | if (!SD.begin(sdChipSelectPin)) | ||
+ | { | ||
+ | Serial.println("Card failed, or not present"); | ||
+ | // don't do anything more: | ||
+ | return; | ||
+ | } | ||
+ | Serial.println("card initialized."); | ||
+ | |||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | // put your main code here, to run repeatedly: | ||
+ | int recordNow = digitalRead(recordingButtonInputPin); | ||
+ | if (recordNow == HIGH) | ||
+ | { | ||
+ | delay(100); // Software debouncing of button | ||
+ | while(digitalRead(recordingButtonInputPin) == HIGH) { | ||
+ | ;// Wait for button release | ||
+ | } | ||
+ | if (isRecording == false) | ||
+ | { | ||
+ | isRecording = true; | ||
+ | digitalWrite(recordingLEDPin, HIGH); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | isRecording = false; | ||
+ | digitalWrite(recordingLEDPin, LOW); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (isRecording == true) | ||
+ | { | ||
+ | int lightStrength = analogRead(ldrInputPin); | ||
+ | File dataFile = SD.open("lightlog.txt", FILE_WRITE); | ||
+ | if (dataFile) | ||
+ | { | ||
+ | dataFile.println(String(lightStrength)); | ||
+ | dataFile.close(); | ||
+ | // print to the serial port too: | ||
+ | Serial.println(String(lightStrength)); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | // if the file isn't open, pop up an error: | ||
+ | Serial.println("error opening lightlog.txt"); | ||
+ | } | ||
+ | delay(1000); // Delay 1 second | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </pre> | ||
+ | = Arduino Hack Night = | ||
+ | == Project 1: Blink == | ||
+ | <pre> | ||
+ | To be completed... | ||
+ | </pre> | ||
+ | |||
+ | [[Category:HOWTO]] |
Latest revision as of 15:54, 17 July 2017
Contents
Presentation
Arduino Quick Start
https://docs.google.com/presentation/d/1PG9YJP-CJ0dU62r9KHZu6RrYr6oOIKasvj2brW6CuD8/edit?usp=sharing
Arduino 101
https://docs.google.com/presentation/d/1sB8RygR-oZyq8jZwiidcsYhblC1duVVDcdwAD0Z3vJI/edit?usp=sharing
Arduino 101 Projects
Project 1
int potInputPin = 0; int servoOutputPin = 11; int smallAngleLEDPin = 2; int largeAngleLEDPin = 4; int minValue = 64; int maxValue = 192; int analogValue = 512; void setup() { pinMode(servoOutputPin, OUTPUT); pinMode(smallAngleLEDPin, OUTPUT); pinMode(largeAngleLEDPin, OUTPUT); analogWrite(servoOutputPin, analogValue); Serial.begin(9600); } void loop() { analogValue = analogRead(potInputPin); Serial.println(analogValue); analogValue = analogValue / 4; Serial.println(analogValue); if (analogValue < minValue) { digitalWrite(smallAngleLEDPin, HIGH); } else if (analogValue > maxValue) { digitalWrite(largeAngleLEDPin, HIGH); } else { digitalWrite(smallAngleLEDPin, LOW); digitalWrite(largeAngleLEDPin, LOW); analogWrite(servoOutputPin, analogValue); } delay(100); }
Project 2
#include <SPI.h> #include <SD.h> int recordingButtonInputPin = 5; int recordingLEDPin = 2; boolean isRecording = false; int ldrInputPin = 1; int sdChipSelectPin = 7; void setup() { pinMode(recordingButtonInputPin, INPUT); Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.print("Initializing SD card..."); // see if the card is present and can be initialized: if (!SD.begin(sdChipSelectPin)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized."); } void loop() { // put your main code here, to run repeatedly: int recordNow = digitalRead(recordingButtonInputPin); if (recordNow == HIGH) { delay(100); // Software debouncing of button while(digitalRead(recordingButtonInputPin) == HIGH) { ;// Wait for button release } if (isRecording == false) { isRecording = true; digitalWrite(recordingLEDPin, HIGH); } else { isRecording = false; digitalWrite(recordingLEDPin, LOW); } } if (isRecording == true) { int lightStrength = analogRead(ldrInputPin); File dataFile = SD.open("lightlog.txt", FILE_WRITE); if (dataFile) { dataFile.println(String(lightStrength)); dataFile.close(); // print to the serial port too: Serial.println(String(lightStrength)); } else { // if the file isn't open, pop up an error: Serial.println("error opening lightlog.txt"); } delay(1000); // Delay 1 second } }
Arduino Hack Night
Project 1: Blink
To be completed...