Coding for ardiuno projects

20140224-183534.jpg

20140224-183526.jpg

01.wpid-20140209_210448.jpgwpid-20140209_211953.jpgwpid-20140209_212017.jpg

02.

wpid-20140209_214933.jpg
int switchState = 0;
void setup () {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2,INPUT);
}
void loop(){
switchState = digitalRead(2);
//this is a comment

if (switchState == LOW){
digitalWrite(3, HIGH);//green LED
digitalWrite(4, LOW); // red LED
digitalWrite(5, LOW); //red LED
}

else { // the button is pressed
digitalWrite(3,LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);

delay(250); //wait for a quarter of a second
//toggl the LEDS
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); //wait for a quarter second
}
} // go back to the beggining of the loop

03. Love-o-meter

wpid-20140209_215849.jpg

const int sensorPin = A0;
const float baselineTemp = 20.0;
void setup(){
Serial.begin(9600); //open a serial port
for(int pinNumber = 2; pinNumber<5; pinNumber++){
pinMode(pinNumber,OUTPUT);
digitalWrite(pinNumber, LOW);
}
}

void loop(){
int sensorVal = analogRead(sensorPin);
Serial.print(“Sensor Value: “);
Serial.print(sensorVal);

//convert the ADC reading to voltage
float voltage = (sensorVal/1024.0) *50;
Serial.print(“, Volts: “);
Serial.print(voltage);
Serial.print(“, degrees C: “);
//convert the voltage to temperature in degrees
float temperature = (voltage – .5) * 100;
Serial.println(temperature);

if(temperature < baselineTemp){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}else if(temperature >=baselineTemp+2 &&
temperature <baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}else if (temperature >=baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
delay(1);
}
04. Color mixing lamp

wpid-20140209_231140.jpg

const int greenLEDPin = 9;
const int redLEDPin = 11;
const int blueLEDPin = 10;

const int redSensorPin = A0;
const int greenSensorPin = A1;
const int blueSensorPin = A2;

int redValue = 0;
int greenValue = 0;
int blueValue =0;

int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue= 0;

void setup(){
Serial.begin(9600);
pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
}

void loop(){
redSensorValue = analogRead(redSensorPin);
delay(5);
greenSensorValue = analogRead(greenSensorPin);
delay(5);
blueSensorValue = analogRead(blueSensorPin);
Serial.print(“Raw Sensor Values \t Red: “);
Serial.print(redSensorValue);
Serial.print(“\t Green: “);
Serial.print(greenSensorValue);
Serial.print(“\t Blue: “);
Serial.print(blueSensorValue);
redValue = redSensorValue/4;
greenValue = greenSensorValue/4;
blueValue = blueSensorValue/4;

Serial.print(“Mapped Sensor Values \t Red: “);
Serial.print(redValue);
Serial.print(“\t Green: “);
Serial.print(greenValue);
Serial.print(“\t Blue: “);
Serial.print(blueValue);
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}0

05. Mood Cue

wpid-20140210_001803.jpg

#include <Servo.h>
Servo myServo;

int const potPin =A0;
int potVal;
int angle;
void setup() {
myServo.attach(9);

Serial.begin(9600);
}

void loop() {
potVal = analogRead(potPin);
Serial.print(“potVal: “);
Serial.print(potVal);
angle = map(potVal, 0, 1023, 0, 179);
Serial.print(“, angle: “);
Serial.println(angle);

myServo.write(angle);
delay(15);
}

06. Light theremin

wpid-20140210_003245.jpg

int sensorValue;
int sensorLow =1023;
int sensorHigh = 0;

const int ledPin = 13;
void setup(){
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
while (millis() < 5000) {
sensorValue = analogRead(A0);
if (sensorValue > sensorHigh) {
sensorHigh = sensorValue;
}
if (sensorValue < sensorLow) {
sensorLow = sensorValue;
}
}

digitalWrite(ledPin, LOW);
}

void loop (){
int pitch =
map(sensorValue, sensorLow, sensorHigh, 50, 4000);

tone(8,pitch,20);
delay(10);
}

07. Keyboard instrument

wpid-20140210_005522.jpg

int buttons[6];
//set up an array with 6 integers

int notes[] = {262,294,330,349};

void setup() {
Serial.begin(9600);
}

void loop() {
int keyVal = analogRead(A0);
Serial.println(keyVal);
if(keyVal ==1023){
tone(8, notes[0]);
}

else if (keyVal >= 990 && keyVal <= 1010){
tone(8, notes[1]);
}
else if(keyVal >= 505 && keyVal <= 515){
tone(8, notes[2]);
}
else if(keyVal = 5 && keyVal <= 10){
tone(8, notes[3]);
}
else{
noTone(8);
}
}

08. Did not need to complete

09. Motorized pinwheel

const int switchPin = 2;
const int motorPin = 9;
int switchState = 0;

void setup() {
pinMode(motorPin, OUTPUT);
pinMode(switchPin, INPUT);
}

void loop(){
switchState = digitalRead(switchPin);

if (switchState == HIGH) {
digitalWrite(motorPin, HIGH);
}
else {
digitalWrite(motorPin, LOW);
}
}

10. Zoetrope

wpid-20140210_151135.jpg wpid-20140210_153534.jpg

11. Crystal Ball

wpid-Snapchat-20140210042932.jpg

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;

void setup() {
lcd.begin(16, 2);
pinMode(switchPin,INPUT);
lcd.print(“Ask the”);

lcd.setCursor(0, 1);
lcd.print(“Crystal Ball!”);
}

void loop() {
switchState = digitalRead(switchPin);

if (switchState != prevSwitchState) {
if (switchState == LOW) {
reply = random(8);

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“The Ball says:”);
lcd.setCursor(0, 1);
switch(reply){
case 0:
lcd.print(“yes”);
break;
case 1:
lcd.print(“Most Likely”);
break;
case 2:
lcd.print(“Certainly”);
break;
case 3:
lcd.print(“Outlook good”);
break;
case 4:
lcd.print(“unsure”);
break;
case 5:
lcd.print(“ask again”);
break;
case 6:
lcd.print(“doubtful”);
break;
case 7:
lcd.print(“NO”);
break;
}
}
}
prevSwitchState = switchState;
}

12. Knock Lock

wpid-Snapchat-20140210050917.jpg

#include <Servo.h>
Servo myServo;
const int piezo = A0;
const int switchPin = 2;
const int yellowLed = 3;
const int greenLed = 4;
const int redLed = 5;

int knockVal;
int switchVal;

const int quietKnock = 10;
const int loudKnock = 100;

boolean locked = false;
int numberOfKnocks = 0;

void setup(){
myServo.attach(9);
pinMode(yellowLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(switchPin, INPUT);
Serial.begin(9600);
digitalWrite(greenLed, HIGH);
myServo.write(0);
Serial.println(“the box is unlocked!”);
}

void loop(){
if(locked == false){
switchVal = digitalRead(switchPin);
if(switchVal == HIGH){
locked = true;
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
myServo.write(90);
Serial.println(“The box is locked!”);
delay (1000);
}
}

if(locked == true){
knockVal = analogRead(piezo);
if(numberOfKnocks < 3 && knockVal > 0){
if(checkForKnock(knockVal) == true){
numberOfKnocks++;
}
Serial.print(3-numberOfKnocks)

;
Serial.println(“more knocks to go”);
}
if(numberOfKnocks >= 3){
locked = false;
myServo.write(0);
delay(20);
digitalWrite(greenLed,HIGH);
digitalWrite(redLed,LOW);
Serial.println(“the box is unlocked!”);
}
}
}
boolean checkForKnock(int value){
if(value > quietKnock && value < loudKnock){
digitalWrite(yellowLed, HIGH);
delay(50);
digitalWrite(yellowLed,LOW);
Serial.print(“valid knock of value”);
Serial.print(value);
return true;
}
else {
Serial.print(“bad knock value”);
Serial.println(value);
return false;
}
}

13. touchy feely lamp

wpid-20140222_001001.jpg

I could not figure out how to get this one to work the coding was not working no matter what way I had gone about it. I had set it all up but could not get the coding to go through

int threshold = 1000;
const int ledPin = 12;

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
long sensorValue = capSensor.capacitiveSensor(30);
Serial.println(sensorValue);

if(sensorValue > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite, LOW);
}
delay(10);
}

14.wpid-20140221_235147.jpg

void setup() {
Serial.begin(9600);
}
void loop() {
Serial.write(analogRead(A0)/4);
delay(1);
}

image processing.serial.*;
Serial myPortl
PImage logo;
int bgcolor = 0;
void setup() {
colorMode(HSB, 225);
logo = loadImage(“http://arduino.cc/logo/png&#8221;);
size(logo.width, logo.height);
println(“Available serial ports:”);
println(Serial.list());
myPort =
new Serial(this, Serial.list()[10], 9600);
}
void draw() {
if (myPort.available() > 0) {
bgcolor = myPort.read();
println(bgcolor);
}
background(bgcolor, 255, 255);
image(logo, 0, 0);
}

same thing happened with this, while entering in the code the parts that should had lit up remained darkened then while trying to fit in the code, it would not produce the code needed to continue with the coding itself.

20140224-183509.jpg

20140224-183520.jpg

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: