Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I am using the sketch below to send the bytes of the frame buffer display.screen of 1536 bytes in size, to the computer over serial communication. The result of it to my java program is a byte array with values between 127 and -128. The result I am seeking of in java program is a byte array with values between 0 and 1. How could I declare the value of i to be an unsigned byte?

#include <TVout.h>
#include <video_gen.h>
#include <SoftwareSerial.h>

#define BAUD (9600)
#define W 128
#define H 96
#define compute ((TV.hres()/8) * TV.vres())

TVout TV;

SoftwareSerial Sserial(0, 1);

void setup() {
  Sserial.begin(BAUD);  
  delay(1000);
  TV.begin(PAL, W, H);
  initOverlay();
  initInputProcessing();
}  

void initOverlay() {
  TCCR1A = 0;
  TCCR1B = _BV(CS10);  
  TIMSK1 |= _BV(ICIE1);
  EIMSK = _BV(INT0);
  EICRA = _BV(ISC11);
}

void initInputProcessing() {
  ADCSRA &= ~_BV(ADEN); 
  ADCSRB |= _BV(ACME); 
  ADMUX &= ~_BV(MUX0); 
  ADMUX |= _BV(MUX1);
  ADMUX &= ~_BV(MUX2);
  ACSR &= ~_BV(ACIE);  
  ACSR &= ~_BV(ACIC); 
}

ISR(INT0_vect) {
  display.scanLine = 0;
}

void loop() {
  delay(1000);
  TV.capture();
  for (int i=0; i<compute; i++)
    {
      Sserial.write(display.screen[i]);
    }
  delay(3000);
}
share|improve this question
There are no unsigned bytes in Java. Since you want to have values between 0 and 1, maybe what you really want is an array of float values? – starblue Apr 28 '12 at 12:01

1 Answer

up vote 2 down vote accepted

It's up to the receiving program to interpret the data as an 8-bit fraction.

On the wire, the data is just eight bits; there is no inherent signed-ness or implied binary-point (or any other interpretation). Your java program will have to interpret the byte as an unsigned fraction, if that's what you need, something like [pseudo-code]: frac = (float)(unsigned)b/256.;.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.