Thanks for your question. Barcode is a technology that is very common but there are many aspects that are not clear to the vast majority of people (ie, 4 b/w stripes signify a number). The project is about making children grasp these concepts, not about making them read a barcode.
Hi! I'd like to share a project developed by me and other two students at the Copenhagen Institute of Interaction Design (CIID, www.ciid.dk). It is a project that aims at teaching barcodes to children through the use of music.
Video:
It has been developed in 4 days during Massimo Banzi/David A. Mellis/David Gauthier's Physical Computing class. Feedback is welcome! Thanks.
Variables are not stored in program memory (flash), they are stored in RAM, and the mega168 only has 1k of RAM. [...] If your array is constant you can store it in program space (which is 14k) by including <avr/pgmspace.h> and using the PROGMEM attribute in your array declaration, but it looks like in your case this wouldn't help you.
If you need to store a large array, maybe you should look into purchasing an external RAM module.
Thanks for the info! It's good to know that pgmspace.h exists. Where can I find a RAM module? Is it fast as interna RAM?
I'm trying to run the following program; it compiles, but it never starts. :'( Reducing the array size makes it run but I need to use a pretty big array.
1000 short ints should not overflow ATmega168 memory, should they? 1000 * 16 bit = 1000 * 2 byte = 2000 byte (compiling this program returns: " 2838 bytes (of a 14336 byte maximum)")
Note that you initialize pos to zero, and then call a function that only delays if pos is less than -360 (which is immediately false). This will cause your function to immediately exit and proceed to one that drives the motors in the other direction until pos is greater than 360 (in this direction the while loop is not true immediately and you actually get a delay). When you switch directions you need to switch the less-than operator to a greater-than operator.
I'm so sorry it was such a stupid mistake! Thanks so much for your help!
This may or may not be a valid thought, but doesn't using a for loop add overhead, so you're not getting an accurate result for how long it takes to do a multiple or add?
I get your point but in my program (the one described in the first post) all the operations happen inside for loops, so I guess that in this case it's important not to mitigate the loop overhead.
You can use timer1 which can be accurate to a fraction of a microsecond but its easier just doing a big loop of floating points and using millis. If you do a say ten thousand fp operations you should get a pretty good estimate of how long one would take
I used a program to separately calculate ADD and MULT time. The results were: 12 microseconds and 5 microseconds respectively.
My code has 28 multiplies and 36 sums for a total of 572 microseconds. In addition it must be considered that I'm working with matrixes and that I'm handling 4 PWM outputs and one analog input.
...Is it enough to exceed 3 milliseconds?
PS: This is the code I wrote (the printDouble function was created by mem!):
Code:
float val = 0.03; float add = 0.012; float mult = 1.008; float time = 0; int prec = 30000; long start = 0; long end = 0; long total = 0;
void setup() { digitalWrite(13, HIGH); }
void loop() {
//ADD start = millis(); for( int i = 1; i < prec; i++ ) { val = val + add; } end = millis(); total = end - start;
Serial.begin(9600); Serial.print("It has taken "); Serial.print( total ); Serial.println(" milliseconds in total."); time = (total*1000)/prec; printDouble( time, 6 ); Serial.println(" microseconds per one ADD");
//MULTIPLY start = millis(); for( int i = 1; i < prec; i++ ) { val = val*mult; } end = millis(); total = end - start;
Serial.begin(9600); Serial.print("It has taken "); Serial.print( total ); Serial.println(" milliseconds in total."); time = (total*1000)/prec; printDouble( time, 6 ); Serial.println(" microseconds per one MULT");
digitalWrite(13, LOW); while(1); }
void printDouble( double val, byte precision){ // prints val with number of decimal places determine by precision // precision is a number from 0 to 6 indicating the desired decimial places // example: printDouble( 3.1415, 2); // prints 3.14 (two decimal places)
Serial.print (int(val)); //prints the int part if( precision > 0) { Serial.print("."); // print the decimal point unsigned long frac; unsigned long mult = 1; byte padding = precision -1; while(precision--) mult *=10;
Simply because I didn't read it on the datasheet... but I guess I can trust Massimo!
Quote
If you are using an original arduino you can see by yourself by looking at the quartz next to the processor. It should say S16B00K7 the 16 means 16MHz
Nice!
Quote
in terms of floating point speed it all depends on the quality of the software implementation as the processor doesn't have a floating point coprocessor we are using the one that comes with avr-gcc so you should check if there is any indication on the avr-libc website
PS: I thought I might calculate how much time it takes for two floats to be added or multiplied but I need a more precise version of the millis() function... does a version of millis() that work with microseconds (instead of milliseconds) exist? Thank you.
I've read that Arduino runs at 16 MHz (btw is that true?) and I thought it would not be a problem to execute (more or less) 60 float operations every 1 ms: it indeed is a problem and I have to slow down to 250 Hz (once every 4 ms).
Do you think that this is an expected result? Thanks