Enter Your Project for a chance to win an Oscilloscope Grand Prize Package for the Most Creative Vision Thing Project! | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
While I was waiting for the analogue multiplexers to come that I need to make the rest of the LDR camera I decided to add an 8x8 array LED display as I just happened to have one (thanks shabaz ). This is a fun display using a HT16K33 to drive an 8x8 LED array using the SPI interface. Unfortunately on the Arduino Nano the two SPI signals SCL and SDA are on pins A4 and A5 so I could not use two of the analogue inputs. This is not a problem for the final camera as with the 16-to-1 multiplexers I am hoping to use I will only need four of the analogue inputs, so it wasn't worth messing about trying to overcome this problem for this test-of-concept implementation.
These matrix LED arrays have been around for some time although I had never used any before, so the first step was to download the Arduino Libraries. I'm not familiar with this process despite having downloaded Arduino libraries before (but then I just clicked on a link and it all seemed to happen without too much of my intervention) and the descriptions do seem to assume that you mostly know what is going on. As I didn't it took me two days to work it all out. The test programmes provided with the matrix displays worked but when I tried to write my own, it didn't. That took me another day to work out - I had to define the display as an 8x8 matrix to do the individual pixel control that I wanted. Obvious when I had worked it out, but not at all clear from the documentation.
All I did then was to amend my previous LDR to serial monitor programme to include outputting to a row of pixels on the matrix display (only 6 of them as two analogue inputs are being used by the display), see below. The display works by setting values in a memory buffer using the drawPixel(x,y,colour) function and then transferring the buffer contents to the LED matrix using writeDisplay() function. I'm still not entirely sure how it works but at least it does what I want it to do. It is not a clever programme in any way but it is just for testing. Once I implement the analogue multiplexers I will see about making it more compact and more generalised.
threshold = 50;
while (1)
{
matrix.clear(); // clear display
LDRvalue = analogRead(LDR0pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 0, 1);
else
matrix.drawPixel(0, 0, 0);
LDRvalue = analogRead(LDR1pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 1, 1);
else
matrix.drawPixel(0, 1, 0);
LDRvalue = analogRead(LDR2pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 2, 1);
else
matrix.drawPixel(0, 2, 0);
LDRvalue = analogRead(LDR3pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 3, 1);
else
matrix.drawPixel(0, 3, 0);
// LDRvalue = analogRead(LDR4pin);
Serial.print("xx");
Serial.print(" ");
// LDRvalue = analogRead(LDR5pin);
Serial.print("xx");
Serial.print(" ");
LDRvalue = analogRead(LDR6pin);
Serial.print(LDRvalue);
Serial.print(" ");
if (LDRvalue > threshold)
matrix.drawPixel(0, 6, 1);
else
matrix.drawPixel(0, 6, 0);
LDRvalue = analogRead(LDR7pin);
Serial.println(LDRvalue);
if (LDRvalue > threshold)
matrix.drawPixel(0, 7, 1);
else
matrix.drawPixel(0, 7, 0);
matrix.writeDisplay(); // write the changes we just made to the display
delay(500);
} /* while */
The LEDs can only be ON or OFF which is disappointing as I was hoping for a grey scale LED matrix display. The documentation for the display does indicate that there are 16 levels of LED brightness but this applies to the whole display rather than being able to control individual pixels. It might be possible to achieve some level of grey scale control of individual LEDs by rapidly updating the display to create a kind of PWM for each LED but that's a lot of software I do not want to write at present.
I have set a threshold light level of 50 so any level below 50 which is bright light, has the LED off and any value above 50 which is shadow turns the LED on. The video below shows all this in operation. I still output the LDR data to the serial monitor and the xx values indicate the locations of the A4 and A5 inputs from the LDR that are used for the SPI interface.
All I need now is for the rest of the LDRs and analogue multiplexers to arrive and I shold be able to make the rest of the LDR camera. After that it will be the ANN (artificial neural network) for for recognising the content of the images captured. You never know, it might all just work.
Dubbie
Top Comments