GLAZUNOV: Explanation

Explanation

Glazunov runs on one motor and 11 sensors, all hooked up to a single rather overworked Handy Board, along with a computer to output the notes.

The motor starts off the motion of several chain links interconnected by gears, thereby leading a sheet of paper through the machine, under a row of sensors, and out the other side.

As for the sensors, we used reflectance sensors, which are able to differentiate between black and white. Each sensor was programmed to play the appropriate note upon detecting black.

The 11 sensors are hooked to both digital and analog sensor ports. The analog sensors read number ranging from 0 to 255 where as the digital sensors are set to 128. The digital sensors provides two outputs, true (0) and false (1), therefore we have to treat them as if they are switches. The sensors check to see if the switches are turned on before it executes the rest of the code.


The code runs as follows:

global [black]

to read-paper
setblack 100
; assume reflectance sensor is plugged into sensor 0
loop [
read-note 0 67
read-note 2 65
read-note 3 64
read-note 5 62
read-note 6 60
read-note 7 59
read-note 8 57
read-note 10 55
read-note 11 53
read-note 13 52
read-note 14 50
]
end

to read-note :sens :pitch
if (not(switch :sens))
    [resett
    waituntil [or (switch :sens) (timer > 5000)]
    send :pitch
    send timer / 100
            print timer]
end

to play-music
loop [
make "pitch recc 
if (and (:pitch > 49) (:pitch < 99))
  [show "pitch= show :pitch
   make "dur recc 
    if (and (:dur > 0) (:dur < 50))
     [show "dur= show :dur
      note :pitch :dur wait 1]]
]
show "done
end

to recc
loop[
make "x .recc
if :x > -1 [output :x]]
end

'to read-paper' is a code that allows the computer to receive information from the Handy Board to play the notes that correspond to each sensor. 'Setblack 100' is the threshold for the sensors. When a sensor reads a number that is greater than 100, it will play the appropriate note. The space in between the sensors and the paper had to be adjusted so that the sensor could read the black electrical tape. When the sensors are too far away from the paper the numbers will read above 100 even before the sensors detect the black electrical tape. Therefore the Handy Board will be confused and not read the notes. In 'to read-paper,' the first number next to read-note represents the sensor and the second number represents the pitch. The range of the pitches are from 50 to 67.

digital input: sensor 14 => Note nubmer: 50 - D
digital input: sensor 13 => Note number: 52 - E
digital input: sensor 11 => Note number: 53 - F
digital input: sensor 10 => Note number: 55 - G
digital input: sensor 8 => Note number: 57 - A
analog input: sensor 7 => Note number: 59 - B
analog input: sensor 6 => Note number: 60 - C
analog input: sensor 5 => Note number: 62 - D (an octave higher than sensor 14))
analog input: sensor 3 => Note number: 64 - E (an octave higher than sensor 13)
analog input: sensor 2 => Note number: 65 - F (an octave higher than sensor 11)
analog input: sensor 0 => Note number: 67 - G (an octave higher than sensor 10)

On the actual machine, the sensor that plays the lowest note is placed on the far right, and the sensor to the left of the first sensor plays a note whole step higher. The notes increment by half/whole step, right to left, for the rest of the sensors.

'to read-note' detects the length of the note. First, the machine checks to see if the sensors detect a number above the threshold. When the sensors detect an object that is dark enough, the timer is started. After the timer is set the sensor waits until it sees white paper. As soon as the sensor detects white it stops the timer. The Handy Board then sends the information of the pitch and the duration of the note to the computer. The computer then reads the two numbers, pitch and duration, and sends the information to 'to read-paper.'

'to play-music' is the actual command that you call upon on the computer when you want to start the machine to run and process the notes. When you type in 'play-music' on the computer, set the menu to 'read-paper', and start the Handy Board the machine will start looking for a black spot.