Thursday, November 10, 2011

Test on Wednesday 16/11/11

There will be a test on some of the topics covered during our course on the date above.

It will be a written test but you can refer to anything on the Internet and will need to be able to write and run programs in the Arduino environment. Please bring your Arduinos to the test and also bring a LDR, light dependent resistor as you will be asked to write a program that will involve analogue input.

There will be a question about the front page of the Atmel pdf for the AVR328. You should be able to explain most of the features mentioned there.

There will be a question about different embedded buses and their main features.

You will be asked to write a schematic for a robotic circuit.

There will be other questions on work covered in class.

There will be a revision class the day before so bring any questions along to that.

Sunday, November 6, 2011

Toggling a LED

This is a better way of getting the classic LED toggling Blink program to turn the LED to to alternate state. I'd seen this elsewhere but forgot about it.It was recently suggested by David Beath, a student in our class.

boolean ledState = 0; //in the setup

digitalWrite(13,(ledState = !ledState)); // in the loop

Tuesday, November 1, 2011

PROGMEM example

#include <avr/pgmspace.h>
 char buffer [5];
 word serialCount;
void setup(void)
{
    Serial.begin(38400);
    Serial.println("\nPress space bar .");
//    while (Serial.read() != 32)   delay(1); // Wait for space
 
}
const int mydata[10][10] PROGMEM = {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', 'A',
    '1', '1', '2', '3', '4', '5', '6', '7', '8', 'B',
    '2', '1', '2', '3', '4', '5', '6', '7', '8', 'C',
    '3', '1', '2', '3', '4', '5', '6', '7', '8', 'D',
    '4', '1', '2', '3', '4', '5', '6', '7', '8', 'E',
    '5', '1', '2', '3', '4', '5', '6', '7', '8', 'F',
    '6', '1', '2', '3', '4', '5', '6', '7', '8', 'G',
    '7', '1', '2', '3', '4', '5', '6', '7', '8', 'H',
    '8', '1', '2', '3', '4', '5', '6', '7', '8', 'I',
    '9', '1', '2', '3', '4', '5', '6', '7', '8', 'Z' };

void loop(void) {
    int i,j;
    byte n;
    Serial.println("\nData by Rows.");
    for (i=0; i < 100;i++) {
  // Serial.println(" ");
        if ((i %8)==0) Serial.print("|");
        if ((i %16)==0) Serial.println("");
   n = pgm_read_byte_near(i);
 // Serial.print(n, HEX);
          Serial.print(" ");
          sprintf(buffer, "%02x", n);
          Serial.print(buffer);
          serialCount++;
          
         // Serial.print("\t"); 
     }
    
    Serial.println(" ");
    Serial.println("\nData by Columns.");
    for (i=0; i < 10; i++) {
   Serial.println(" ");
   for (j=0; j < 10; j++) {
  n = pgm_read_word_near(&mydata[j][i]);
  Serial.print(n, BYTE);
   }
    }
    Serial.println(" ");    setup();    Serial.println(" ");  //start over
}