Roy’s 6th Class

July 15th, 2006

output vs. final value of x.

final value might not be output in the case of x++

int y=x++ assign x to y and then increase x by one…

error would occur “%d %d”, x, y (error if “xy” because not string)

 

import java.io.*;

public class ListContentsOfFile
{
   public static void main( String[] args )
   {
      if( args.length == 0 )
         System.out.println( “No files specified” );
      else
         for( int i = 0; i < args.length; i++ )
            listContentsOfFile( args[ i ] );
   }

   /****************************************

    * List the contents of filename
    *************************************

   public static void listContentsOfFile( String fileName )
   {
      FileReader theFile;            // The class use for reading character files
      BufferedReader fileIn //object of buffered reader// = null;  // Read text from a character-input stream
      String oneLine;                // Copy each line from the file here

      try
      {
         theFile = new FileReader( fileName );//way of connect
         fileIn = new BufferedReader( theFile );

         while( ( oneLine = fileIn.readLine() ) != null )//somewhat nested not null println
            System.out.println(  oneLine );//impt to have println
      }
      catch( IOException ioe )
      {
         System.out.println( ioe );
      }
   }
}

int []x=new int [10];
create array of type int call it x and do 10 of them initialize all to 0
//with a string you make a reference…

main(String//string []//is an array args//keyword )

int [] a,b,c,d;//several arrays
int e[],f,g;//one array e; others not arrays

anything after .java applies to main. print(args.length);
errr… on this, check out.

int[]z=new int[5];//not value for each

char[] name={’b',’o',b}’
int[]z={25,30,1,5};

can reassign value of z

 

 

Roy’s 5th Class

July 8th, 2006

going over counter
substantiate variable outside of
for(i=0;i<10;i++;)
if you want to say more about counter.
can’t define in both places (outside and inside)

public class Box
{
  private float width;
  private float height;
  private float depth;

  private String color;
  private String material;

  Box (String clr) //constructors which make a class
  {
   color=clr;
   }

  Box (float wi, float he, float de)
  {
    width=wi;
    height=he;
    depth=de;
  }
 

this gives characteristics that can then be used when you set the qualities

Calender

July 4th, 2006

Thurs

DIA
http://www.diaart.org/dia/visitor/index.html 

Sat- Warm Up

http://www.ps1.org/ps1_site/index.php?option=com_content&task=view&id=55&Itemid=99&limit=1&limitstart=1 
Sun

In conjunction with the exhibition Into Me / Out of Me, renowned artist Carolee Schneemann will present a lecture on her work and lead a discussion with the audience on the themes of the exhibition, which is on view throughout the first floor of P.S.1, from June 25 through September 25, 2006. Err.. maybe

Thurs July 13th
Ani DiFranco 7-10
Yo La Tengo at Prospect Park

Tues, July 18th 

Talib Kwelli 

Midi-2

June 29th, 2006
Pretty Cool.  As one presses fsr pitch increases.  Switch is one note.
Prob. encountered was just the volume out of speakers was super soft
and initially thought the wiring wasn't working.  Must look to see LED closely.
with LED
// The switch is on Arduino pin 10:
#define switchPin 10 //note to self to look up #define
// Middle C (MIDI note value 60) is the lowest note we’ll play:
#define middleC 60
//  Indicator LED:
#define LEDpin 13

// Variables:
char note = 0;
// The MIDI note value to be played
int AnalogValue = 0;
// value from the analog input
int lastNotePlayed = 0;
// note turned on when you press the switch
int lastSwitchState = 0;
// state of the switch during previous time through the main loop
int currentSwitchState = 0;

void setup() {
//  set the states of the I/O pins:
pinMode(switchPin, INPUT);
pinMode(LEDpin, OUTPUT);
//  Set MIDI baud rate:
Serial.begin(31250);
blink(3);
}

void loop() {
//  My potentiometer gave a range from 0 to 1023:
AnalogValue = analogRead(0);
//  convert to a range from 0 to 127:
note = AnalogValue/8;
currentSwitchState = digitalRead(switchPin);
// Check to see that the switch is pressed:
if (currentSwitchState == 1) {
//  check to see that the switch wasn’t pressed last time
//  through the main loop:
if (lastSwitchState == 0) {
// set the note value based on the analog value, plus a couple octaves:
// note = note + 60;
// start a note playing:
noteOn(0×90, note, 0×40);
// save the note we played, so we can turn it off:
lastNotePlayed = note;
digitalWrite(LEDpin, HIGH);
}
else    // if the switch is not pressed:
//  but the switch was pressed last time through the main loop:
if (lastSwitchState == 1) {
//  stop the last note played:
noteOn(0×90, lastNotePlayed, 0×00);
digitalWrite(LEDpin, LOW);
}
}

//  save the state of the switch for next time
//  through the main loop:
lastSwitchState = currentSwitchState;
}

//  plays a MIDI note.  Doesn’t check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(char cmd, char data1, char data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}

// Blinks an LED 3 times
void blink(int howManyTimes) {
int i;
for (i=0; i< howManyTimes; i++) {
digitalWrite(LEDpin, HIGH);
delay(100);
digitalWrite(LEDpin, LOW);
delay(100);
}
}

Midi Lab

June 29th, 2006
Want to see if can connect to some midi read device.
Will ask around.  Seeing serial print out.
Pics of my board and img from Tom's site (smaller). Also, how one can
hear what's happening. Cool.
toms board
// Variables:
char note = 0;            // The MIDI note value to be played

void setup() {
//  Set MIDI baud rate:
Serial.begin(31250);
}

void loop() {
// play notes from F#-0 (30) to F#-5 (90):
for (note = 30; note < 90; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(char cmd, char data1, char data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}

DC motor

June 29th, 2006

am going to have to wait one more day for Hbridge (hopefully)

Quote

June 29th, 2006

People pay for what they do, and still more for what they have allowed themselves to become. And they pay for it very simply; by the lives they lead.
James A. Baldwin

Serial with Mouse

June 27th, 2006
board
breadboard
Errr... wondering if my board is not correct.
Did a reading serially of one sensor on a-0 and was hoping to see
some response via processing window. Now trying to adjust my
board with the not so many sensors I have.  To take it back a step.
Why is there no response in processing window.  Will try more tomorrow.
import processing.serial.*;  int bgcolor;
// Background color int fgcolor;			     // Fill color Serial port;
// The serial port int[] serialInArray = new int[3];
// Where we'll put what we receive int serialCount = 0;
// A count of how many bytes we receive int xpos, ypos;
// Starting position of the ball boolean firstContact = false;
// Whether we've heard from the microcontroller  void setup() { size(256, 256);  // Stage size noStroke();
// No border on the next thing drawn
// Set the starting position of the ball (middle of the stage) xpos = width/2; ypos = height/2;
// Print a list of the serial ports, for debugging purposes: println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my  Keyspan adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using. port = new Serial(this, Serial.list()[0], 9600); port.write(65);
// Send a capital A to start the microcontroller sending }  void draw() { background(bgcolor); fill(fgcolor);
// Draw the shape ellipse(xpos, ypos, 20, 20);
// If no serial data has beeen received, send again until we get some.

// (in case you tend to start Processing before you start your
// external device): if (firstContact == false) { delay(300); port.write(65); } }
void serialEvent(Serial port) { // if this is the first byte received,
// take note of that fact: if (firstContact == false) { firstContact = true; }
// Add the latest byte from the serial port to array: serialInArray[serialCount] = port.read(); serialCount++;
// If we have 3 bytes: if (serialCount > 2 )
{ xpos = serialInArray[0]; ypos = serialInArray[1]; fgcolor = serialInArray[2];
// print the values (for debugging purposes only): println(xpos + "t" + ypos + "t" + fgcolor);
// Send a capital A to request new sensor readings: port.write(65); // Reset serialCount: serialCount = 0; } }

Serial Lab

June 27th, 2006
int analogPin = 0;
int analogValue = 0;            // outgoing ADC value

void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
}

void loop()
{
// read analog input, divide by 4 to make the range 0-255:
analogValue = analogRead(analogPin);
analogValue = analogValue / 4;
Serial.println(analogValue, DEC);
// pause for 10 milliseconds:
delay(10);
}

See in several formats:
int analogPin = 0;
int analogValue = 0;                // integer to print

void setup() {
// open serial communications at 9600 bps
Serial.begin(9600);
}

void loop() {
// read the analog inoput, divide by 4:
analogValue = analogRead(analogPin) /4;

// print in many formats:
Serial.print(analogValue, BYTE);     // Print the raw binary value analogValue
Serial.print('t');                  // print a tab
Serial.print(analogValue, BIN);      // print the ASCII encoded binary analogValue
Serial.print('t');                  // print a tab
Serial.print(analogValue, DEC);      // print the ASCII encoded decimal analogValue
Serial.print('t');                  // print a tab
Serial.print(analogValue, HEX);      // print the ASCII encoded hexadecimal analogValue
Serial.print('t');                  // print a tab
Serial.print(analogValue, OCT);      // print the ASCII encoded octal analogValue
Serial.println();                    // print a linefeed and carriage return

delay(10);
}

Roy’s 4th Class

June 24th, 2006

x++ keeps original value in print out statement but in memory adds one.
++x immediately add and print out 12
z+=10 shorthand for z+z=20

chapt 3, 4, 5, 6, 7 rd chapters listed

Chapter 5. Control Statements: Part 2
— pages 180 – 192 (§ 5.1 — 5.5)
— pages 200 – 213 (§ 5.7 — 5.9)
— The switch statement
Chapter 3. Introduction to Classes and Objects
— pages 82 – 104 (§ 3.1 — 3.8)
Chapter 4. Control Statements: Part 1
— pages 135 – 153 (§ 4.8 — 4.10)
Chapter 5. Control Statements: Part 2
— pages 191 – 200 (§ 5.6)
Chapter 7. Arrays
— pages 286 – 325 (§ 7.1 — §7.12)          

test: increment, truth tables, logical/relational operators, for loops, dot class what it represents (different compilers)– byte code (java code native to compiler) for c programs final output is exe for pc, out for mac, doesn’t have compiler other than what is there for native operating sys.

Ternary Operator

public static void main (etc)
{
  try
    {
      int number;
     BifferedReader input
          = new BufferedReader (
             new InputStream Reader (System.in));

     System.out.println(”Enter an integer:”);
     number = Integer.parseInt (input.readLine());

     System.out.println(
           number + “is” +        // these are things that are concatonated (sp?)
           ( (number>1000)?        // is this true// “>1000″ : //else//  ”<=1000")); 
    }
    catch (IOException ioe)()
    }

The Pragmatic Programmer

for (exp1;//initialize// exp2;//test// exp3;//iteration//)
for (int i=1;i<=10;i++)
print(i);                 //scope is until end of it being true

main
{}
get
{}
set
{}
globals are above main. Things inside get and set can’t see each other.  Independent classes. Name an int in for loop only alive in for loop vs. declaring it earlier, aka before for loop.

i +=5;     //moving in multiples of 5

for (int row=0;row<=3; row++)
     for (int col=0; col <=3; col++)
           print (rowd ” ” + col);
outer loop goes col * row amount of times (16)
col does it it row amount of times (4)

for (…)
    for(…)
        if
        {col etc
         }

switch (input)
{
      case 0:
             print (”you entered 0″);
             break;
      case 1:
             print (”you entered 1″);
             break;
      default:
             print (”you didn’t enter 0 or 1″);

}