Saturday, 18 April 2015

Tasks 25-28

25. Same as 24 but don't display the dice numbers, rather say how many throws it takes to get to 100 sixes. Then start again each time you get to 100 sixes.
25A. Write a program that takes the output of the voltage between two resistors into an analog port pin for reading. This voltage will be between 0 and 5 volts. Output the number you get between 0 and 1023 to the screen. (Try different resisitors and predict what will happen.)
25B. Same as 25A but this time make one of the resistors a variable resisitor so that your output will change.
26. RS232 Check out this site  and others like it so you can write about 100 words in your blog on the protocol. Include in your text two pictures of pin-outs or relevant frames.

27. A very short talk to the class about an Arduino command that you can use in your programs. Check out the word allocated to you in the wiki part of our blog. Study the word and give a 2-3 slide presentation telling the class what the word does and give an example of the way it's used in Arduino code. Any other tips or relevant information should be presented. The talk should last about a minute.

28. Write a delay subroutine in avr assembler using AVR studio 4 that lasts fro exactly 50 milliseconds.Refer to a post above in this blog called assembler delays.
 

Tasks 21-24(complete)

21. Randoms. Write a program to output random numbers between 0 and 100 to the serial terminal.
//Program to output random numebrs between 1-100 to the serial port
// Arron Dick
// 02/06/2015


void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop(){
  int randomNumber=random(1,100+1);
 Serial.println(randomNumber); 
}

22. Write a program to output the throwing of a dice every second and display the number that comes up.

// Program to output a dice number every second
// Arron Dick
// 02/06/2015


void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop(){
  int randomNumber=random(1,6+1);
 Serial.println(randomNumber);
 delay(1000);
}

23. Same as 22 but display as well the number of sixes that you have thrown so far.
// Program to output a dice number every second
// Arron Dick
// 02/06/2015

int sixesSoFar=0;
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop(){
  int randomNumber=random(1,6+1);
  if (randomNumber==6){
   sixesSoFar++; 
  }
  Serial.print("Dice throw: ");
 Serial.println(randomNumber);
 
 Serial.print("Sixes so far: ");
 Serial.println(sixesSoFar);
 
 delay(1000);
}

24. Same as 23 but speed it up and stop when you get to 25 sixes.
// Program to output a dice number every second
// Arron Dick
// 02/06/2015

int sixesSoFar=0;
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop(){
  if (sixesSoFar<25){
    int randomNumber=random(1,6+1);
    if (randomNumber==6){
     sixesSoFar++; 
    }
    Serial.print("Dice throw: ");
   Serial.println(randomNumber);
 
   Serial.print("Sixes so far: ");
   Serial.println(sixesSoFar);
 
   delay(100);
  }
}