Keith Bizek's log

Assignment 8.1 Picture

posted Aug 22, 2010, 2:52 PM by Unknown user

I had to upload the picture for this assignment separately because I don't know how to access my camera on the school's laptop.


Assignment 8.1

posted Aug 22, 2010, 2:28 PM by Unknown user

I made a simple 4-key piano that plays a C Major Arpeggio. 

Arduino Code:
#include "pitches.h"  //includes relevant library
int switch1 = 7  //declares variables
int switch2 = 6
int switch3 = 5
int switch4 = 4

void setup() {
  pinMode(switch1, INPUT); //sets pins to inputs
  pinMode(switch2, INPUT);
  pinMode(switch3, INPUT);
  pinMode(switch4, INPUT);
  pinMode(switch5, INPUT);
}

void loop() {
  if (digitalRead(switch1) == HIGH) {  //if the first switch is pressed, 
    tone(3, NOTE_C3, 50);                //play C3
  }
  if (digitalRead(switch2) ==HIGH) {   //if the second switch is pressed,
    tone(3, NOTE_E3, 50);                //play E3
  }
  if (digitalRead(switch3) == HIGH) { //if the third switch is pressed,
    tone(3, NOTE_G3, 50);                //play G3
  }
  if (digitalRead(switch4) == HIGH) {  //if the fourth switch is pressed,
    tone(3, NOTE_C4, 50);                //play C4
  }
}


I downloaded Fritzing, but nothing happens when try to open the file. I see if I can figure it out and post the Fritzing picture later.

Assignment 7.4

posted Aug 22, 2010, 12:32 PM by Unknown user

This took a little while to get but it turned out pretty well. Sometimes the potentiometers will be a little unresponsive. 

Arduino Code:

int pot1 = 1; //delcare variables
int pot2 = 2;
int val = 0;

void setup() {
  Serial.begin(9600); //data will ne sent and received 9600 bps
}

//I will be using the punctuation method for this code

void loop() {
  val = analogRead(pot1);  //read the first potentiometer and store it in val
  Serial.print(val, DEC); // print the valuse just stored
  Serial.print(",");      //print a comma to organize data
  
  val = analogRead(pot2); //read the second potentiometer and store it in val
  Serial.println(val, DEC); //print the value just stored
}

Processing Code:

import processing.serial.*;  //import the processing library
Serial myPort;  //delcare variables
float xpos;
float ypos;

void setup() {
  size (500, 500); //set the window siae to 500x500
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n'); //store values in a buffer
  background(255); //sets the background color to white
}
void draw() {
  fill(0); //sets the fill color to black
  stroke(0);//sets the outline color to black
  ellipse(xpos, ypos, 3, 3); //draw a circle at the designated postion
}

void serialEvent(Serial myPort) {
  String myString = myPort.readStringUntil('\n'); // read the buffer
  if (myString !=null) {
    myString = trim(myString);
    int sensors[]= int(split(myString, ',')); //split string at commas
    for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++){
    print ("Sensor" + sensorNum + ":" + sensors[sensorNum] + "\t"); //print values
    }
    println(); 
    if (sensors.length > 1) {
      xpos = map(sensors [1], 0, 1023, 0, 500); // set values so circles stays in window
      ypos = map(sensors [2], 0, 1023, 0, 500);
    }
  }
}
    

August 21

posted Aug 21, 2010, 6:43 PM by Unknown user

Worked on lesson 7 but encountered a problem that requires assistance from Mr. Dickie

Assignment 7.2

posted Aug 21, 2010, 4:35 PM by Unknown user

The punctuation and handshaking methods are two ways to organize and make sense of data sent from multiple inputs. In Arduino, the punctuation method creates a new line of values every time the loop function runs, making the serial monitor more orderly and easy to read. In Processing the values are read and control the sketch in a much more understandable fashion. The handshaking method sets up a system of communication in which the Arduino will run the establishContact function until it senses that there is new serial data available. When it does, it will switch over to the void loop function and run it as long as there is new data to be read. Processing will "ask" Arduino for data in the serialEvent function and when it receives said data it will print the values and control the sketch in the same way as the punctuation method.

Both methods are extremely useful and make using multiple sensors much more understandable. Although both are very effective, one is most likely better than the other; which one depends on the specific situation. This is mainly because the punctuation method is simpler but runs continuously. If the situation allows, the simpler method would be ideal. However, sometimes the more intricate solution is required. 

August 15

posted Aug 15, 2010, 7:11 PM by Unknown user

Today I finished lesson 5 and 6 

Assignment 6.3

posted Aug 15, 2010, 6:55 PM by Unknown user

I played around with the code for awhile and found a map setting that gave me a similar range as the potentiometer. 

int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 13;   // select the pin for the LED
int val = 0;       // variable to store the value coming from the sensor

void setup() {
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
  Serial.begin(9600);   //sends and receives data at 9600 bps
}

void loop() {
  val = analogRead(potPin);    // read the value from the sensor
  val = map(val, 0, 301, 0, 1023);
  digitalWrite(ledPin, HIGH);  // turn the ledPin on
  delay(val);                  // stop the program for some time
  digitalWrite(ledPin, LOW);   // turn the ledPin off
  delay(val);                  // stop the program for some time
  Serial.println(val);
}

Assignment 6.2

posted Aug 15, 2010, 5:50 PM by Unknown user

My homemade potentiometer did not work anywhere near as well as the actual one. As you can see in the video it was erratic no matter where I placed the alligator clip, speeding up and slowing down unpredictably.  The real potentiometer provided regular, even resistance and created a steady pattern, as opposed to the sporadic, uneven nature of its homemade counterpart. 

 

YouTube Video

Assignment 6.1

posted Aug 15, 2010, 5:01 PM by Unknown user

int potPin = 2;
int val = 0;

void setup()
{
}

void loop()
{
  for (int led = 13; led >=5; led--)
  {
    val = analogRead(potPin); 
    pinMode(led, OUTPUT);
    digitalWrite(led, HIGH);
    delay(val);
    digitalWrite(led, LOW);
    delay(val);
  }
  for (int led = 5; led <=13; led++)
  {
    val = analogRead(potPin);
    pinMode(led, OUTPUT);
    digitalWrite(led, HIGH);
    delay(val);
    digitalWrite(led, LOW);
    delay(val);
  }
}

Assignment 5.4

posted Aug 15, 2010, 3:35 PM by Unknown user

Arduino Code:

char val;                          // Data received from the serial port
 int ledPin = 2;                  // Set the pin to digital I/O 2
 int ledPin2 = 4;                //set the pin to digital I/O 4
 
 void setup() 
 {
   pinMode(ledPin, OUTPUT);        // Set pin as OUTPUT
   Serial.begin(9600);             // Start serial communication at 9600 bps
 }
 
 void loop() 
 {
   if (Serial.available()) 
   {                              // If data is available to read,
     val = Serial.read();         // read it and store it in val
   }
   if (val == 'H') 
   {                             // If H was received
     digitalWrite(ledPin, HIGH); // turn LED1 on
   } 
   Untitled Post
   else if (val == 'K') {        //If K was recieved
     digitalWrite(ledPin2, HIGH);//turn LED2 on
   }
   
     else if (val == 'P') {
       digitalWrite(ledPin, HIGH); //If P was received 
       digitalWrite(ledPin2, HIGH);//turn both LEDs on
     }
   
   else if (val == 'L') {
     digitalWrite(ledPin, LOW);  // If is received
     digitalWrite(ledPin2, LOW); //turn both LEDs off
   }
   delay(10);                   // Wait 10 milliseconds for next reading
 }

Processing Code:

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;        // Data received from the serial port

void setup() 
{
  size(400, 400);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  background(255);
  if ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150)) {  
                                  // If mouse is over the first square,
    fill(225, 0, 0);              // change color and
    myPort.write('H');            // send an H to indicate mouse location

else if ((mouseX >= 200) && (mouseX <= 300) && (mouseY >= 50) && (mouseY <= 150)) {
                                   // If mouse is over the second square,
  fill(0, 255, 0);                 //change color and 
  myPort.write('K');               // send a K to indicate mouse location
}

else if ((mouseX >= 50) && (mouseX <=150) && (mouseY >= 250) && (mouseY <= 350)) {
                                  //If mouse is over the third square,
  fill (0, 0, 255);               // change the color and
  myPort.write('P');              // send a P to indicate mouse location
}

  else {                          // If mouse is not over any square,
    fill(255, 255, 0);            // change color and
    myPort.write('L');            // send an L otherwise
  }
  
  rect(50, 50, 100, 100);         // Draw the first square
  rect(200, 50, 100, 100);        // Draw the second square
  rect(50, 250, 100, 100);        // Draw the third square
  
}

1-10 of 22