Tuesday, October 27, 2009

TSVETA [ Code 1/6, 2/6, 3/6 and 6/6 ]

Code 1/6

int led = 5;
int buttonpin = 10; //set up pin for the button
int flex = 3; //set up pin for flex sensor/photo cell
int buttonstate = HIGH;


void setup(){
pinMode(led, OUTPUT);
pinMode(buttonpin, INPUT);//buttonpin and flex sensor/photocell pin to be recognized as input
pinMode(flex, INPUT);
Serial.begin(9600);
}


void loop(){
int state = analogRead(flex); //read analog value from sensor and assign it to state
Serial.println(state);
int button = digitalRead(buttonpin); //
if (button != buttonstate){ //check if state has been changed and if yes
digitalWrite(led, HIGH); // turn led on
delay(state*2); // double the value from analog input and use to determine delay
digitalWrite(led, LOW);//turn led off
delay(state*2);
}

}

Code 2/6


int buttonpin = 10;//set up pin for the button
int photo = 3;//set up pin for photo cell
int buttonstate = HIGH;//initial state for later comparison



void setup(){
for (int thisPin = 2; thisPin <= 7; thisPin++) {
pinMode(thisPin, OUTPUT); //going through the leds to set them as output
}
pinMode(buttonpin, INPUT); //buttonpin and photo pin to be recognized as input
pinMode(photo, INPUT);

Serial.begin(9600);//begin serial port

}

void loop(){

int button = digitalRead(buttonpin); //get the data from the button and assign it to interger button
if (button != buttonstate) { //check if the data is different than the initial setup
int analogvalue = analogRead(photo); //read analog data from photo cell and store it in int analogavalue
Serial.println(analogvalue);
for (int thisPin = 2; thisPin <= 7; thisPin++) { //go through leds from lower number to higher to light them up fluidly


digitalWrite(thisPin, HIGH); // turn the pin on:
delay(analogvalue); // use the analog data to set up delay - dynamically changing
digitalWrite(thisPin, LOW); // turn the pin off:
delay(analogvalue);
//set switch to 0 - stop reading flex
}
delay(20);

for (int thisPin = 7; thisPin >= 2 ; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH); // turn the pin on:
delay(analogvalue); // use the analog data to set up delay - dynamically changing
digitalWrite(thisPin, LOW); // turn the pin off:
delay(analogvalue);
}

}

}


Code 3/6

int led = 10;//set up pin 10 for the button
int photo = 3;//set up pin for flex sensor/photo cell
void setup(){
pinMode(led, OUTPUT);//led pin will be outputing info
pinMode(photo, INPUT);//photocell pin will be receiving input
Serial.begin(9600);//begin serial port }
void loop(){
int delaytime = analogRead(photo); //assign analog data received to temporary variable
for(int i=0; i<= 225; i++){ //use i as a counter
analogWrite(led, i); //output to gradually light up led
delay(delaytime); //use value from photocell to set up delay time, dynamically changing }
for(int i=225; i>=0; i--){
analogWrite(led, i); //output to gradually turn off led
delay(delaytime); } }


Code 6/6


int pinArray[] = { 2, 3, 4 }; //declare first array that includes pins 2 through 4
int pinArray2[] = {5, 6, 7}; //declare a second array that includes pins 5 through 7
int arrayVal = 2; //declare a variable to hold the array values; int arrayVal2 = 0;
int switchPin = 10;
int switchstate = HIGH;
int photo = 3;

void setup() {
pinMode(switchPin, INPUT);
pinMode(photo, INPUT);
for ( arrayVal = 2; arrayVal >= 0; arrayVal-- ){ //use the for statement to go through all numbers from the array - from 4 to 2
pinMode(pinArray[arrayVal], OUTPUT); //set all pins from that array to be output }
for ( arrayVal2 = 0; arrayVal2 <=2 ; arrayVal2++ ){ //use the for statement to go through all numbers from the array - from 5 to 7
pinMode(pinArray2[arrayVal2], OUTPUT); //set all pins from that array to be output }
Serial.begin(9600);
}

void loop() {
int state = digitalRead(switchPin); //check switch state
int analogvalue = analogRead(photo); //take analog values and assign to local variable
Serial.println(analogvalue);
if (state != switchstate && analogvalue ){
arrayval =" 2;">=0; arrayVal--){ //test pins in backwards order (from higher number to lower)
digitalWrite(pinArray[arrayVal], HIGH); //light them up fluidly
delay(30);
digitalWrite(pinArray[arrayVal-1], HIGH);
Delay(30);
digitalWrite(pinArray[arrayVal], LOW);
delay(30);
}
for (arrayVal2 = 0; arrayVal2 <= 2 ; arrayVal2++){ //test pins going from lower number to higher
digitalWrite(pinArray2[arrayVal2], HIGH); //light up led in a fluid manner
delay(30);
digitalWrite(pinArray2[arrayVal2+1], HIGH);
delay(30);
digitalWrite(pinArray2[arrayVal2], LOW);
delay(30);
}
}
if ( state == switchstate ){ //if there has been change in the switch mode
for (arrayVal = 2; arrayVal>=0; arrayVal--){ //test pins in backwards order (from higher number to lower)
digitalWrite(pinArray[arrayVal], HIGH);
delay(analogvalue); //use the analog value received to determine
digitalWrite(pinArray[arrayVal-1], HIGH);
delay(analogvalue);
digitalWrite(pinArray[arrayVal], LOW);
delay(analogvalue);
}
for (arrayVal2 = 0; arrayVal2 <= 2 ; arrayVal2++){ //test pins going from lower number to higher
digitalWrite(pinArray2[arrayVal2], HIGH);
//light up led in a fluid manner
delay(analogvalue);
digitalWrite(pinArray2[arrayVal2+1], HIGH);
delay(analogvalue);
digitalWrite(pinArray2[arrayVal2], LOW);
delay(analogvalue); }
if (state != switchstate && analogvalue > 60){ //if the analog value is more than 60 and switch state hasn't been changed
for (arrayVal = 2; arrayVal>=0; arrayVal--){ //test pins in backwards order (from higher number to lower)
digitalWrite(pinArray[arrayVal], HIGH);
delay(analogvalue);
digitalWrite(pinArray[arrayVal-1], HIGH);
delay(analogvalue);
digitalWrite(pinArray[arrayVal], LOW);
delay(analogvalue);
}
for (arrayVal2 = 0; arrayVal2 <= 2 ; arrayVal2++){ //test pins going from lower number to higher
digitalWrite(pinArray2[arrayVal2], HIGH); //light up led in a fluid manner
delay(100);
digitalWrite(pinArray2[arrayVal2+1], HIGH);
delay(100);
digitalWrite(pinArray2[arrayVal2], LOW);
delay(100);
}
}
/* //////////////////HERE IS WHERE I STILL HAVE ISSUES TO SOLVE BUT THE GOAL IS TO USE SINGLE ANALOG VALUE, LET IT GROW IT OVER TIME AND USE THAT TO GRADUALLY TURN THE LEDS ON FOR A SOFTER FEELING AND LOOK/////////////////////////////////// if (state==switchstate && analogvalue>=200){ int myvalue = analogvalue; for(arrayVal=0; arrayVal<=2; arrayVal++){ //test pins going from lower number to higher for( myvalue =0; myvalue<=255; myvalue++){ analogWrite(pinArray[arrayVal], myvalue); //light up led in a fluid manner delay(20); analogWrite(pinArray[arrayVal+1], 255-myvalue); delay(20); //analogWrite(pinArray[arrayVal], myvalue); //delay(2); } for (arrayVal2 = 2; arrayVal2 >= 0; arrayVal2--){ //test pins going from higher number to lower number digitalWrite(pinArray2[arrayVal2], myvalue); delay(20); digitalWrite(pinArray2[arrayVal2-1], myvalue); delay(20); digitalWrite(pinArray2[arrayVal2], myvalue); delay(20); } } }*/ } }

Shanna B Exercise #3 (Resistor Light Value)

int ledPin = 9; // Declare pin9 for LED
int photoPin = 1; // variable resistor on analog pin 1
int val = 0;

void setup() // run once, when the sketch starts
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT); // set led pin 9 as OUTPUT
pinMode(photoPin,OUTPUT); // set analog pin 1 as OUTPUT
}

void loop() { // run over and over again
val = analogRead(photoPin); // set val equal to the resistor input

if(val == LOW) {
digitalWrite(ledPin, HIGH);
delay(100);

} else {
digitalWrite(ledPin, LOW);
}
Serial.println(val);
} video

Sunday, October 18, 2009

PWM LED

int ledPin = 10;
int analogPin = 0;
int analogValue = 0;

void setup(){
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(analogPin, OUTPUT);
}


void loop() {
  analogValue = analogRead( analogPin);
  
  analogWrite(ledPin, analogValue);
  
/*  if(analogValue == HIGH){
  analogWrite(ledPin, LOW);
  delay(200);
  }
  
  else
{
  analogWrite(ledPin, HIGH);
}*/
Serial.println(analogValue);
}
video

D.collins_Homework_Exercise 3

int ledPin = 9; // declare Pin 9
int analogPin = 2; // Analog pin 2

void setup(){} // no setup needed

void loop() //Function read the analog value and set a delay time and controls the speed at which an LED brightens and dims
{
for (int i=100; i<=10; i++) // give value of 255 for variable "i"
// The above "for loop" function starts the integer "i" at 0, and tests to see if i is still less or equal to 255 and if true, increments "i" by 1 and executes the enclosed statements. i++ is the same as i=i +1 or i by +1

{
analogWrite(ledPin, i); // sets led pin 9 brightess level to i
delay(delayVal()); // generate time value and pauses
}
for (int i=255; i>=0; i--) // if i is 255 then i should be 0
{
analogWrite(ledPin, i); // sets led pin 9 brightess level to i
delay(delayVal()); // generate time value and pauses
}
}

int delayVal() // declare variable for delay time value
{
int v; // create temporary variable
v = analogRead(analogPin); // read analog value
v /= 20; // convert 0-1024 to 0-128
return v; // returns final value
} video

D.collins_Classwork_Exercise 3

int ledPin = 12; // Declare pin 11 for LED
int photoPin = 3; // variable resistor on analog pin 0
int photoValue = 0;
int boo = 0;

void setup() // run once, when the sketch starts
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT); // set led pin 12 as OUTPUT
pinMode(photoPin,OUTPUT); // set analog pin 3 as OUTPUT
}

void loop() { // run over and over again
photoValue = analogRead(photoPin); // set val equal to the resistor input

boo = (photoValue/ 3) * 40;



Serial.println(boo);
analogWrite(ledPin, boo);
delay(100);
} video

LED Array

int timer = 100; 
int ledPins[] = {2,3,4,5,6 }; 
int pinCount = 5; 
int analogPin = 0;
int analogValue = 0;

void setup() {
Serial.begin(9600);
for (int whatPin = 0;  whatPin<5;>
pinMode(ledPins[whatPin], OUTPUT);
}
}
void loop() { 
int analogValue = analogRead(analogPin);

Serial.println(analogValue);
if(analogValue >= 50) {
for (int whatPin = 0;  whatPin<5;>

  digitalWrite(ledPins[whatPin], HIGH);
delay(timer);

digitalWrite(ledPins[whatPin], LOW);
}}
  if(analogValue <= 49) {
for (int whatPin = 5;  whatPin>0; whatPin--) {

digitalWrite(ledPins[whatPin], HIGH);
delay(timer);

digitalWrite(ledPins[whatPin], LOW);
}
}
}

video

Shanna B Exercise #1 (Resistor Timing)

int led1Pin = 9; // PWM pin 9 for the LED 1
int led2Pin = 10; // PWM pin 10 for the LED 2
int analogPin = 2; // variable resistor on analog pin 2

void setup(){ }

void loop()
{
for (int i=0; i<=255; i++) // ascending value for i
{
analogWrite(led1Pin, i); // sets brightess level to i
delay(delayVal()); // gets time value and pauses
}
for (int i=255; i>=0; i--) // descending value for i
{
analogWrite(led1Pin, i); // sets brightess level to i
delay(delayVal()); // gets time value and pauses
}

for (int i=0; i<=255; i++)
{
analogWrite(led2Pin, i);
delay(delayVal());
}
for (int i=255; i>=0; i--)
{
analogWrite(led2Pin, i);
delay(delayVal());
}
}

int delayVal()
{
int v; // create temporary variable
v = analogRead(analogPin); // read analog value
v /= 10; // this convert 0-1024 to 0-129
return v; // returns final value
}
video

Shanna B Assignment #2

int led1Pin = 9; // declare pin 9
int led2Pin = 10; // declare pin 10
int switchPin = 2; // the switch is connected to pin 2
int buttonState; // declare a variable to hold the button state

void setup()
{
pinMode(switchPin, INPUT); // Set the switch pin as INPUT
pinMode(led1Pin, OUTPUT); // LED pin 9 as OUTPUT
pinMode(led2Pin, OUTPUT); // LED pin 10 as OUTPUT


}

void loop() {
buttonState = digitalRead(switchPin); // read the initial state
if(buttonState == HIGH) { // LED (wave) if statement
for (int i=0; i<=20; i++) // set loops for 20 times { digitalWrite(led2Pin, LOW); digitalWrite(led1Pin, HIGH); delay(100); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); delay(100); digitalWrite(led2Pin, LOW); } delay(2000); // pauses for 2 seconds } } video

Wednesday, October 14, 2009

Shanna B Assignment #1

*/

int ledPin = 13; // LED connected to digital pin 13

int ledPin2 = 8; // LED connected to digital pin 8

int ledPin3 = 7; // LED connected to digital pin 7
const int analogPin = 0; // pin that the sensor is attached to
const int threshold = 100; // an arbitrary threshold level that's in the range of the analog input


// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);

pinMode(ledPin2, OUTPUT);

pinMode(ledPin3, OUTPUT);

// initialize serial communications:
Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(50); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(50); // wait for a second

digitalWrite(ledPin2, HIGH); // set the LED on
delay(8); // wait for a second
digitalWrite(ledPin2, LOW); // set the LED off
delay(8); // wait for a second

digitalWrite(ledPin3, HIGH); // set the LED on
delay(200); // wait for a second
digitalWrite(ledPin3, LOW); // set the LED off
delay(200); // wait for a second

// read the value of the potentiometer:
int analogValue = analogRead(analogPin);

// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);
delay(250);
}
else {
digitalWrite(ledPin,LOW);
delay(20);
}

// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin2, HIGH);
delay(375);
}
else {
digitalWrite(ledPin2,LOW);
delay(100);
}

// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin3, HIGH);
delay(20);
}
else {
digitalWrite(ledPin3,LOW);
delay(700);
}

// print the analog value:
Serial.println(analogValue, DEC);
}

video

Shanna B Assignment #3

int ledPin = 9; // declare Pin 9
int analogPin = 2; // Analog pin 2

void setup(){} // no setup needed

void loop() //Function read the analog value and set a delay time and controls the speed at which an LED brightens and dims
{
for (int i=0; i<=300; i++) // give value of 255 for variable "i" // The above "for loop" function starts the integer "i" at 0, and tests to see if i is still less or equal to 255 and if true, increments "i" by 1 and executes the enclosed statements. i++ is the same as i=i +1 or i by +1 { analogWrite(ledPin, i); // sets led pin 9 brightess level to i delay(delayVal()); // generate time value and pauses } for (int i=300; i>=0; i--) // if i is 255 then i should be 0
{
analogWrite(ledPin, i); // sets led pin 9 brightess level to i
delay(delayVal()); // generate time value and pauses
}
}

int delayVal() // declare variable for delay time value
{
int v; // create temporary variable
v = analogRead(analogPin); // read analog value
v /= 50; // convert 0-1024 to 0-128
return v; // returns final value
}

video

Tuesday, October 13, 2009

Putra's 3 Exercises



Variable Resistor: Light Value

int ledPin = 11; // Declare pin 11 for LED
int photoPin = 0; // variable resistor on analog pin 0
int val = 0;

void setup() // run once, when the sketch starts
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT); // set led pin 11 as OUTPUT
pinMode(photoPin,OUTPUT); // set analog pin 0 as OUTPUT
}

void loop() {
// run over and over again
val = analogRead(photoPin); // set val equal to the resistor input

if(val == LOW) {
digitalWrite(ledPin, HIGH);
delay(100);

} else {
digitalWrite(ledPin, LOW);
}
Serial.println(val);
}




Variable Resistor: LED Array

int timer = 100; // Number for the time - the higher the number, the slower the timing.
int ledPins[] = {8,9,10,11,12 }; // an array of pin numbers to which LEDs are attached
int pinCount = 5; // the number of pins
int analogPin = 0; // the pin that the potentiometer is attached to
int analogValue = 0;

void setup() { // loop over the pin array and set them all to output:
int thisPin;
pinMode(analogPin, INPUT);
for (int thisPin = 0; thisPin < style="color: rgb(102, 51, 0);">// the array elements are numbered from 0 to (pinCount - 1).
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest
int analogValue = analogRead(analogPin);
if(analogValue >= 50) {
for (int thisPin = 0; thisPin < style="color: rgb(102, 51, 0);">// loop from the highest pin to the lowest
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}
}






Variable Resistor: Timing


int led1Pin = 9; // PWM pin 9 for the LED 1
int led2Pin = 11; // PWM pin 11 for the LED 2
int analogPin = 0; // variable resistor on analog pin 0

void setup(){ }

void loop()
{
for (int i=0; i<=255; i++) // ascending value for i
{
analogWrite(led1Pin, i); // sets brightess level to i
delay(delayVal()); // gets time value and pauses
}
for (int i=255; i>=0; i--) // descending value for i
{
analogWrite(led1Pin, i); // sets brightess level to i
delay(delayVal()); // gets time value and pauses
}

for (int i=0; i<=255; i++)
{
analogWrite(led2Pin, i);
delay(delayVal());
}
for (int i=255; i>=0; i--)
{
analogWrite(led2Pin, i);
delay(delayVal());
}
}

int delayVal()
{
int v; // create temporary variable
v = analogRead(analogPin); // read analog value
v /= 7; // this convert 0-1024 to 0-128
return v; // returns final value
}

Andrew Zahn Number Two

This is my movie and code - but I could not get it running - Will check in class video


int ledPins[] = {1,2,3,4};
int potPin = 1;
int potValue = 1;
int timer = 100;

void setup() {
  
int whatPin;

for (int thisPin = 0; thisPin;) 

pinMode(ledPins[whatPin], OUTPUT);
}




void loop() {

potValue = analogRead(potPin);
int Timer1;
int Timer2;


if(potValue >= 50) {
  
for (int whatPin = 0; whatPin  >

digitalWrite(ledPins[whatPin], HIGH);
delay(newTimer1);
digitalWrite(ledPins[whatPin], LOW);

}
}


if(potValue <= 49) {
for (int whatPin = pinCount - 1; whatPin >= 0; whatPin--) {
  

digitalWrite(ledPins[whatPin], HIGH);
delay(Timer2);
digitalWrite(ledPins[whatPin], LOW);

}
}
}

Andrew Zahn Number Two

Andrew Zahn Number One

video

int potpin = 0;
int ledpin = 11; 
int ledvalue = 0;
int potvalue = 0;

void setup(){

pinMode(ledpin, OUTPUT);

}


void loop(){
  
  potvalue =analogRead(potpin);
  ledvalue = potvalue / 4;
  analogWrite(ledpin, ledvalue);
  delay(1);
}

Monday, October 12, 2009

John's 10/14 Assignments

Assignment #1:

Video:


Code:


Assignment #2:

Video:


Code:


Assignment #3:

Video:


Code:
(Shout out to Kyle who helped me out with this.)

Friday, October 9, 2009

Exercise 3

Exercise 3


video




First, i give variables for the LED pin, the photo pin, and the 2 values. Then i set up 6 variables equal to eventually 6 different blinking patterns. in the void setup i set the LED pin to output, and the serial Statement. Now, in the void loop, i set photoValue to equal to analog read the photo pin when called. Light value will equal photovalue divided by 4 so that it can be read in between 0 and 8 i believe(depending on the resistor). Now, analog write the led pin to the photoValue, and print this. the next are 6 if statements saying if it is reading 1, do this speed, if 2, do this speed, and so on.. up to 6. Then the delay of 1 so that it does not read it as fast.

Exercise 2

Exercise 2


video



I must give credit to Joe Cohen for help with some of this Code.

First, i am setting a variable for timer which is 50, then i am making 2 arrays with alternating pins, making 2 pin counts for each, setting the value for photoPin and photoValue, the next to variables will just be my leds that indicates iether if green is blinking, or if red is blinking. Then analogvalue is set to 0. In the void setup i put a for statement that sais thisPin is 0, less then pin count 1 (3 leds) and adding 1. Then, set the red and green LEDs to output, and then the serial statement. In the void loop, i set photoValue to analog red photoPin whenever it is called. Now is where the magic happens! If photoValue is greater then or equal to 300, for thisPin is 0, greater then pinCount1, and adding 1, then digitalWrite the green pins from 1 to 3, if not then turn them off, also lets print this value. If photoValue is less then 299, for thisPin is pinCount2 -1. and is greater then or equal to 0, subtracting 1 (makes it go the other way), then digitalwrite the YellowPins on a timed sequence called timer. print this. variable ledYellowPin are the red LED pins, yellow was to hard to tell the difference between green in the video. If photo value is greater then or equal to 300, turn green pin on, if not, then shut that off and turn red pin on.



Week Two Exercise 1

Exercise #1


video


First, i am setting up intergers for the led pin, the photo pin, and both values for them (ignore the lightBlink1-6 integers). Now, in the void setup, i am setting up the ledpin to outPut, and set up the serial, to later on print values. here comes the void loop where everythign happens constantly. i am setting photovalue so that every time it is called, it will read photoPin analog-ly which can range in values rather then just HIGH and LOW, (0 and 255) next we are setting lightValue to be photoValue divided by 4 because it dives i believe 1,020 into a scale between 0 to 255 in which it can read. Finally we analog-ly write ledPin to the value of photoValue, and then we print the outcome. (the delay of 1 is so that the computer is not reading it as fast, because there is no point for it to work that hard.)

Thursday, October 8, 2009

Tsveta [ Code 4/6 and 5/6 ]

CODE 4/6 - Lighting LEDs using Array


int ledPin = 3;//declare led pin
int photoPin = 0;//declare the analog reading pin
int photoValue = 0;//declare value to store the analog value
int brightness = 0;//declare variable to store and pass the analog value to the led
void setup() { pinMode(ledPin, OUTPUT);//declare output pin
pinMode(photoPin, INPUT);//declare input pin
Serial.begin(9600); }
void loop() {
photoValue = analogRead(photoPin);//read the analog values from the photocell/flexing sensor
brightness = photoValue;//pass analog value from the analog read varibale to the led brightness variable
Serial.println(brightness);//print value received from the photocell/flexing sensor
analogWrite(ledPin, brightness);//pass the analog value to adjust brightness
delay(200);//remove noise
}

_________________________________________________
--------------------------------------------------------------------------------------

CODE 5/6 - Lighting LEDs using Array
The goal here was to have 3 LEDs in one array and 3 led in a different so I can light them up fast from the center of the row to the ends and when pot turned all the way to the other side then it changes the direction and speed.
The issue was that I could not figure out how to make the two different arrays to be doing the same thing at the same time. That is why I took the i that i used as a delay timer and put actual numbers

int pinArray[] = { 2, 3, 4 }; //declare first array that includes pins 2 through 4
int pinArray2[] = { 5, 6, 7}; //declare a second array that includes pins 5 through 7
int arrayVal = 2; //declare a variable to hold the array values;
int arrayVal2 = 0;
int switchPin = 10;
int switchPin2 = 9;
int switchstate = HIGH;




void setup() {
pinMode(switchPin, INPUT);
pinMode(switchPin2, INPUT);
for ( arrayVal = 2; arrayVal >= 0; arrayVal-- ){ //use the for statement to go through all numbers from the array - from 4 to 2
pinMode(pinArray[arrayVal], OUTPUT); //set all pins from that array to be output
}
for ( arrayVal2 = 0; arrayVal2 <=2 ; arrayVal2++ ){ //use the for statement to go through all numbers from the array - from 5 to 7
pinMode(pinArray2[arrayVal2], OUTPUT); //set all pins from that array to be output
}
}
void loop() {
int state = digitalRead(switchPin);
int state2 = digitalRead(switchPin2);
if ( state != switchstate){
for (arrayVal = 2; arrayVal>=0; arrayVal--){ //test pins in backwards order (from higher number to lower)
//for ( i = 0; i<2000;>
digitalWrite(pinArray[arrayVal], HIGH);
delay(100);
digitalWrite(pinArray[arrayVal-1], HIGH);
delay(100);
digitalWrite(pinArray[arrayVal], LOW);
delay(100);
}
for (arrayVal2 = 0; arrayVal2 <= 2 ; arrayVal2++){ //test pins going from lower number to higher
digitalWrite(pinArray2[arrayVal2], HIGH); //light up led in a fluid manner
delay(100);
digitalWrite(pinArray2[arrayVal2+1], HIGH);
delay(100);
digitalWrite(pinArray2[arrayVal2], LOW);
delay(100);}
}
else{
for(arrayVal=0; arrayVal<=2; arrayVal++){ //test pins going from lower number to higher
digitalWrite(pinArray[arrayVal], HIGH); //light up led in a fluid manner
delay(40);
digitalWrite(pinArray[arrayVal+1], HIGH);
delay(40);
digitalWrite(pinArray[arrayVal], LOW);
delay(40);
}
for (arrayVal2 = 2; arrayVal2 >= 0; arrayVal2--){ //test pins going from higher number to lower number
digitalWrite(pinArray2[arrayVal2], HIGH);
delay(40);
digitalWrite(pinArray2[arrayVal2-1], HIGH);
delay(40);
digitalWrite(pinArray2[arrayVal2], LOW);
delay(40);
}
}
}

Wednesday, October 7, 2009

Joe Cohen's 3 In-Class Exercises

#1

video

/* Code by Wm. Joe Cohen for
Physical Computing Studio */

int ledPin = 5;
int photoPin = 0;
int photoValue = 0;
int lightValue = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(photoPin, INPUT);
Serial.begin(9600);
}

void loop() {
photoValue = analogRead(photoPin);
lightValue = photoValue;
//lightValue = photoValue / 4;
Serial.println(lightValue);
analogWrite(ledPin, lightValue);
delay(100);
}

______________________________________________________

#2

video

/* Code by Wm. Joe Cohen for
Physical Computing Studio */

int timer = 50;
int ledPins[] = {
7, 6, 5, 4, 3 };
int pinCount = 5;
int photoPin = 0;
int photoValue = 0;


void setup() {
int thisPin;
for (int thisPin = 0; thisPin <>
pinMode(ledPins[thisPin], OUTPUT);
}
pinMode(photoPin, INPUT);
Serial.begin(9600);
}


void loop() {

photoValue = analogRead(photoPin);

// lighter environment (values of 30+) moves the LED flow one way
if(photoValue >= 30) {
for (int thisPin = 0; thisPin <>
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
Serial.println(photoValue);
}
}


// darker environment (values of 29-) moves the LED flow the opposite way
if(photoValue <= 29) {
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
Serial.println(photoValue);
}
}
}

______________________________________________________

#3

video

/* Code by Wm. Joe Cohen for
Physical Computing Studio */

int timer = 50;
int ledPins[] = {
7, 6, 5, 4, 3 };
int pinCount = 5;
int photoPin = 0;
int photoValue = 0;

void setup() {
int thisPin;
for (int thisPin = 0; thisPin <>
pinMode(ledPins[thisPin], OUTPUT);
}
pinMode(photoPin, INPUT);
Serial.begin(9600);
}

void loop() {

photoValue = analogRead(photoPin);
int newTimer1;
int newTimer2;

// lighter environment (values of 30+) moves the LED flow one way
// and the LEDs move 10 times slower than 'time'
if(photoValue >= 30) {
for (int thisPin = 0; thisPin <>
newTimer1 = timer * 10;
digitalWrite(ledPins[thisPin], HIGH);
delay(newTimer1);
digitalWrite(ledPins[thisPin], LOW);
Serial.println(photoValue);
}
}


// darker environment (values of 29-) moves the LED flow the opposite way
// and the LEDs move 2 times faster than 'time'
if(photoValue <= 29) {
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
newTimer2 = timer / 2;
digitalWrite(ledPins[thisPin], HIGH);
delay(newTimer2);
digitalWrite(ledPins[thisPin], LOW);
Serial.println(photoValue);
}
}
}