Monday, 28 October 2013

Arduino Starter Kit - Chapter 07 and 08




As you can see, is a lot that I don't post anything so I choose to post 2 chapter. I choose to do this because these projects took more time to built than to explain it.

In this post I'll explain the following chapter of the manual:

07 KEYBOARD INSTRUMENT play music and make some noise with this keyboard
08 DIGITAL HOURGLASS a light-up hourglass that can stop you from working too much
Chapter 07:
In this chapter they introduce the concept of Resistor Ladder.
A Resistor Ladder is an electrical circuit made of repeating unit of resistor, this time we built a R2R Ladder which is a simple way to perform a Digital to Analog conversion (wikipedia docet).


In the top photo you can see the circuit build on the board,
and here the Resistor ladder with the switch in parallel.

In the code section in this chapter they introduce the concept of array. An Array is a way to store different values that are related to each other using only one name.
Like in many other languages, the declaration and the initialisation of an array is made up with the following syntax:

  1. arrayType arrayName[n];
  2. arrayType arrayName[] = {value1,value2,...,valueN}
where arrayType is the type which you want associate to the array (primitive type or an object for example), arrayName is the name, and n is the indexing notation, which represent the max index value you can store in the array. In the second declaration don't require the index notation, but you simply put all the needed value between curly braces and divide each one with a comma.
For retrieve a value inside the array you must call the value using his index inside the array
Syntax:
           varType var = arrayName[index];
remember which the index of the array, when you retrieve the value, start from 0 (zero), so if your maximum index value is 5, in fact the last index is 4 because the first is 0.

In this chapter they present also the noTone() function, which is used to stop any sound from the piezo.
Syntax:
          void noTone(pin)
where pin is the pin of the board with a piezo connected to it.

Here a very poor video of the operation of our keyboard:




Chapter 08:
In this chapter there is only two new things: the Tilt Sensor and the Long data type.

The tilt sensor is a sensor with a small metal ball inside itself, and when you move it, he change his state.
Is like an Accelerometer, but less expensive and give less information (only up/down), in fact the Accelerometer is a tilt sensor it self.

The circuit:

In the code section they introduce another data type.
The millis() function, as explained in the previous chapter, keeps track of the time your arduino has been running in milliseconds. So far you've been using only int data type, and an integer is a 16-bit number and it holds value between -32,768 and 32,768. To holds the return value of millis() in a safe manner you must use long data type. The long data type holds a 32-bit number, thus between -2,147,483,648 and 2,147,483,648 and in his unsigned version holds number between 0 and 4,294,967,295.
Using millis() for more than 32 seconds, as you can see by your self, you need to use a long variable to hold its value.

Here the circuit build and ready to count time. 

I change the time in which the led turn on, because in the original code check if every led is on after 600000 millisecond, so every 10 minute a led turn on. Since I don't want to wait 1 hour to see the operation of our hourglass, I change this variable to 60000 which is only one minute,and a led turn on every 10 second.
Here a video of the operation of this little project:



And, after the video, here a gif of this little project:



In the next chapters we will use a 9V battery for use a motor. Cool things, no?
Ygy Freezone


1 comment:

  1. Wild West Slot Review - Pragmatic Play
    The Wild West slot is a 5 reels, 4 paylines 스포츠 스코어 slot game with free spins, Wild multipliers 해외사이트 and a free spins bonus. Click 바카라 시스템 배팅 the release button 슬롯 가입 쿠폰 below 실시간 바카라 and

    ReplyDelete