dear guys..
i need a help from you.i connect a led in my arduino board.i want to encode that image into binary stream.actually i want to get each pixel values from the pixel array separately and convert its values into binary stream with a serial communication.
what should i do ?
i want to get each pixel values from the pixel array separately
What pixel array would that be ?
This is probably the most incoherent question here that I've seen. (I should know, I've written a few myself). I have no clue what you are trying to do. A pixel, an array of pixels, a video stream?
Explain your project- what do you want it to do.
dear friends
i connect a led in to my arduino board.i need to load a grayscale image and convert it into byte array.because i need binary values of each pixel of my whole image.then i need to blink my led which has connected to arduino ,for its all binary values.
eg:1 st pixel value is 120 ,then send its binary value is 01111000.then led blink serialy 0 1 1 1 1 0 0 0 (low high high high high low low low)
after that as an example 2 nd
pixel value 34 ,then send its binary value is 00100010.then led blink again 0 0 1 0 0 0 1 0 (low low high low low low high low) .
i want to blink all the pixel values through my led sequentialy.
please guide me to do this.what is the way to do this.i know you all good in programing ,i need some help from you
@shone_1994, please do not cross-post. Threads merged.
Is each byte in the file a pixel in the image already?
I'm really curious as to why you want to do this. With any reasonable blink interval so the human eye can see the blinks, it's going to take a month of Sundays to blink its way through anything but the tiniest image.
But let's assume that you have the image available as bytes, and you want to blink each byte bit-by-bit.
The code below is a simple edit of Robin2's esteemed serial input basics Example 1, which bitRead()s the bits out of a character from the monitor, and blinks according to the value. (I used 2 leds, one each for a mark and space.)
So provided you have a means of reading the image in, perhaps from an SD card?, it's really simple to blink the bits of each byte.
// bitread https://forum.arduino.cc/index.php?topic=643630.0
// 30 oct 2019
// shows the bits of a byte input from serial
// From Robin2's tutorial https://forum.arduino.cc/index.php?topic=396450
// Example 1 - Receiving single characters
// then instead of just showing the data, we split out its bits
char receivedChar;
boolean newData = false;
byte markLed = 2;
byte spaceLed = 3;
void setup()
{
pinMode(markLed, OUTPUT);
pinMode(spaceLed, OUTPUT);
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop()
{
recvOneChar();
showNewData();
}
void recvOneChar()
{
if (Serial.available() > 0)
{
receivedChar = Serial.read();
newData = true;
}
}
void showNewData()
{
if (newData == true)
{
Serial.print("This just in ... ");
Serial.println(receivedChar);
for (int i = 0; i < 8; i++)
{
bool theBit = bitRead(receivedChar, i);
Serial.print(i + 1); //bits in ascii tables are usually numbered 1 to 8, not from 0 to 7
Serial.print(":");
Serial.println(theBit);
if (theBit)
{
digitalWrite(markLed, HIGH);
digitalWrite(spaceLed, LOW);
}
else
{
digitalWrite(markLed, LOW);
digitalWrite(spaceLed, HIGH);
}
delay(500);
}
Serial.println("");
newData = false;
}
}