Sunday, April 18, 2010

Week 8: Interrupts

Lab 1: External Interrupts.

TBC

Monday, April 12, 2010

Task 34 - 45



34) Write a program to generate 100 random numbers between 0 and 9 to the screen.

long randNumber;

void setup(){
Serial.begin(9600);

// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));

for(int i = 1; i less than 101; i++)
{
randNumber = random(0, 10);
Serial.print(randNumber);
delay(50);
}
}

35) Same as above but this time put your outputs in a numbered list like this: 1. 7 2. 4.
At first I tried putting all the stuff to be printed out into one line like this:
Serial.print( i + ". " + randNumber);
But the apparently the arduino doesn't like to concatenate. The following is what I did to get it to print out correctly.

for(int i = 1; i less than 101; i++)
{
randNumber = random(0, 10);
Serial.print(i);
Serial.print(". ");
Serial.println(randNumber);

36) Same but also output the average (mean) of the 100 numbers with a suitable message.

Same as above, but after the for loop I have included the average:

//mean =
average = sum/100;
Serial.print("Average = ");
Serial.println(average);

The variables "sum" and "average" are initialised first as doubles = 0;

37) Same but this time see if you can drive the baud rate up as far as possible before the output data gets scrambled. Also, what is the slowest speed the Arduino serial will output at? Write your findings in your blog.

For the randomNumbers code the baud rate min was 9600 and max was 14400. Anything outside of this just brought up random text symbols.

38) Write a program to output the value of your LDR whenever you press the button.

const int buttonPin = 2; // the number of the pushbutton pin

int buttonState = 0; // variable for reading the pushbutton status

int photoCellPin = 0;
int photoCellReading;

void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);

Serial.begin(9600);
}

void loop(){
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
photoCellReading = analogRead(photoCellPin);
Serial.print("analog reading = ");
Serial.print(photoCellReading);
if (photoCellReading less than 10)
{Serial.println(" - Dark");}
else
if (photoCellReading
less than
200)
{Serial.println(" - Dim");}
else
if (photoCellReading
less than
500)
{Serial.println(" - Light");}
else
if (photoCellReading
less than
800)
{Serial.println(" - Bright");}
else
{Serial.println(" - Very Bright");}
delay(1000);

}
else
{
Serial.print("button is off.");
}
delay(1000);
}

(photos to be added)

39) Same as 38 but this time write your output like this :
Reading number 1 is 345
Reading number 2 is 123
Reading number 3 is 876 etc...

A new variable "count" is created at the top.
int count = 0;

void loop(void)
{

//inside if statement for if the button is pushed

count++;
photoCellReading = analogRead(photoCellPin);
Serial.print("Reading number is ");
Serial.print(Count);
Serial.print(" = ");

Serial.print(photoCellReading);


40)Find an interesting article on the YABB news section and provide a screen shot and a short report on why you found it interesting.

10th Anniversary Surprise !
I found it interesting that this forum has been around for 10 years and it seems that they are genuinely valuing their contributors. Seems like a good time to sign up too as they are seem to be hinting to giving something away on the 4th of July.


41) Register for YABB but don't contribute yet. Take a screen shot of part of your registration process to confirm you've done it.



42) Write a short list of rules for a bulletin board like YABB. Watch some thread over two weeks and be ready to make a contribution.

YaBB asks users before they register to agree to certain rules such as "you will not post any material which is false, defamatory, inaccurate, abusive, vulgar, hateful, harassing, obscene, profane, sexually-oriented, threatening, invasive of a person's privacy, or otherwise in violation of ANY law."

and

"You remain solely responsible for the content of your messages, and you agree to indemnify and hold harmless this forum, and any related websites to this forum. We at this forum also reserve the right to reveal your identity (or any information we have about you) in the event of a complaint or legal action arising from any information posted by you. "

or like the Golden rule from the bitlan site "
lease remember the golden rule, and before you do anything, anything, think to yourself, "Will doing this make me look like an idiot?" If the answer is yes, maybe, or even sometimes no, just don't do it. "

simple things to take others into consideration would be good rules for a forum.
These are basic rules for when I use a forum:
  • Corecct speeling (*correct spelling).
  • Correct information (know that what you are contributing is correct).
  • Be polite (No need to be offensive).

43) You'll need to look at some project sites to get some good ideas for your minor and major projects. Some have been shown in class. Write a list of four good project sites and include a link and a screen shot for each with a comment in your blog.



44) Present to the class a report on one of your assigned devices. You need to tell us what it does and give a little demo of it working on a simple Arduino project. Include in your talk at least three Impress or PowerPoint slides on a USB pen or similar.

Completed - Presentation about the piezo buzzer with Andrew. Demonstration was the tune "twinkle twinkle little star".

45)Explore the way your infrared transmitter sends pulses to the receiver. Set up a little demonstration to be marked in class. You may share this project with another person but both members have to know what's going on. Transmission from one Arduino to another is especially excellent.

For this I created a simple IR detector by using the blink code in Arduino. By connecting the IR emitter to pin 13 and ground, it acts as the LED. When it "blinks" it sends out an IR signal. The I connected the positive end of the IR receiver to 3V, an LED positive end to the IR's negative and then connected the negative end of the LED to ground. This circuit means that the LED will "blink" when there is an IR connection. When something interrupts the signal or the signal gets blocked, the LED will not blink.

(photo coming soon).


Sunday, April 11, 2010

Arduino Pro:


This board is designed for advanced users who want to leave a board embedded in a project: it's cheaper than a Diecimila and easily powered by a battery, but requires additional components and assembly.


The Arduino Pro is a microcontroller board based on the ATmega168 (datasheet) or ATmega328 (datasheet). The Pro comes in both 3.3V / 8 MHz and 5V / 16 MHz versions. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a battery power jack, a power switch, a reset button, and holes for mounting a power jack, an ICSP header, and pin headers. A six pin header can be connected to an FTDI cable or Sparkfun breakout board to provide USB power and communication to the board.

The Arduino Pro is intended for semi-permanent installation in objects or exhibitions. The board comes without pre-mounted headers, allowing the use of various types of connectors or direct soldering of wires. The pin layout is compatible with Arduino shields. The 3.3V versions of the Pro can be powered with a battery.

The Arduino Pro was designed and manufactured by SparkFun Electronics.

This information was taken from: http://arduino.cc/en/Main/ArduinoBoardPro