Thursday, January 8, 2015

NCSS 2015 - Day 4


Lecture 6: Polling again. We've learned about interrupts as a remedy for some of the disadvantages of polling and today we learned about adding timeouts to inputs --> keeping track of time.
millis() is a function that keeps track of milliseconds for the loop function so far. Millis returns a long integer so there is a possibility of overflow (but admittedly not for 49 days!) if statements checking on the value of millis should not have exact values because you can't predict a value of the milliseconds because of the processes coming before, so always use a range.
Then we moved on to communications and I was back in 2nd year uni desperately trying to keep my protocols straight and not doing a very good job of it. We discussed the SPI and I2C (called I-squared-C). These are two protocols for communicating between the Arduino and particular peripherals or other Arduinos. I really wasn't very sure about all of that so I'm going to have to do some research -- and quickly.
By Arvind Sanjeev (http://maker.diyhacking.com/)
[CC BY-SA 4.0
(http://creativecommons.org/licenses/by-sa/4.0)],
via Wikimedia Commons

Lab 5: UART and SPI (Oh My!) We first connected up two Arduinos in pairs and tried to send and receive messages between them in serial. Then we tried to have a button on one Arduino turn on a light on the other Arduino. Success!! A good lab.
The SPI stuff was apparently broken and needed another couple of lines of code which someone was working on. I had some of my questions answered by the tutors and then it was time to head back for lunch. (Two of the boys are trying to hook up two arduinos to play a MIDI rendition of Europe's "The Final Countdown" with full chords. It's a bit of an in-joke but still very impressive in terms of a challenge.


Lecture 7: Theme for this lecture... "You'd better know what you are doing!" Our lecturer keeps saying this about the "relaxed" attitude of the C compiler. There are a couple of instances where we've discussed breaking the program with empty arguments and weird data type assignments and they will still compile but who knows what they'll do in the actual run-time.
First thing we covered was enumerated data types. You can create your own data types for things such as Three-way boolean ("troolean?") like True False and underfined. States of a game or system (vending machine example coming) enumerations are pretty close to named integer value. There is no real object oriented stuff in C. There are some classes that have methods within the language but you can't write your own unless you want to write your own compiler.  Importantly you can enumerate a record (called a structure) and create an array of records.

Vending Machine example: A vending machine is an embedded system that needs to change states at different points. First it's waiting for a wake up signal. Once it's woken with the insertion of a coin it needs to detect the value of the coin. It then waits for another coin. When it receives another coin it detects and then tallies the total, if the correct total has not been reached it continues in this loop. Once a correct value or greater has been received it waits for selection, once selection has happened it then delivers the selection and then tallies and delivers change. Each of these stages need a different set of sensors and actuators so the processor needs to keep track of which ones are needed. This could be enumerated this way...
enum states_vending {
  waiting;
  detecting;
  adding;
  selection;
  delivery;
}
You can then use these in if statements to shift between one state and the next with some simplicity.

Lab 6: I missed a bit of this lab. Some colleagues and my family turned up. I probably needed the break. I got my accelerometer hooked up (wiring nightmare - note to self and everyone else, despite sounding like a good idea staples don't act as wires on a solderless breadboard.) It was just detecting x y z enough for me to show it to my kids before we walked down to Glebe for dinner.

Important Stuff Learned:
sprintf http://www.cplusplus.com/reference/cstdio/sprintf/
String. functions http://arduino.cc/en/Reference/StringObject

Evening Activity: Family came and whisked me away for dinner - Yay! Everyone else had free time including a board game championship.

Murder Game: Dead for most of the day. A new game started while I was at dinner. It's basically the same as the last one except you don't have a specific target which means it's a free-for-all. I'm not entirely sure of how it works (missed the briefing) but there were a couple of people designated vampires and werewolves at the beginning of the game. Here's the bit I'm unsure about...
Vampires turn people into vampires if they "kill" them
Werewolves turn people into werewolves
Werewolves kill vampires entirely
Vampires kill werewolves entirely
People can kill werewolves and vampires if they have some kind of weapon (not literal, there are paper thingies floating around)
I'm not sure what werewolves do to werewolves because I thought they would kill them but there seemed to be a whole pack of werewolves on the prowl this evening. - Pack animals?
I really don't want to be as paranoid this time!

Missing the site visits tomorrow to go for a swim. I saw them last year.

No comments:

Post a Comment