Changes

Jump to: navigation, search

Week 4 Lab

1 byte removed, 04:34, 21 April 2009
modifying for rudimentary keyboard control
}
}
* EXPLANATION: What I have done is change the <code>Serial.read()</code> and <code>analogWrite()</code> from before. Now we are reading a <code>char</code> rather than a <code>byte</code> from the Serial port, and we are checking whether this character it reads is one of the characters between '0' and '9': a letter on the keyboard was pressed, it is one of the numbers? If it is (<code>if((val>='0')&&(val<='9'))</code>) then we will set the speed of the motor proportionally.
* Compile and upload this sketch to the board, and try it out. Start the Serial Monitor again, and try sending the numbers 0-9 on the keyboard, the motor should speed up and slow down appropriately.
* EXPLANATION: What did we just do? The problem was that in our original Dimmer code, the microcontroller was looking just at the binary value of the data it was receiving. So, if we typed the number 0, which happens to have a binary value of ___ in the ASCII table, it will set the speed to that value, not to 0. We changed the program so the microcontroller is looking for the specific characters, '0' to '9', and then doing the appropriate math to set the output to the right speed.
=== controlling from a Processing app ===

Navigation menu