Brightness threshold without ofxOpenCv

Hi,
I am trying to get a pixelated image from camera that would be just Black and white (no gray pixels).
I managed to modify some code I found online that I am posting.
I managed to control the brightness somehow but I can’t figure out how to tell the pixels to be either black or white…
any help?

many thanks!

//--------------------------------------------------------------
void ofApp::setup(){
// w = ofGetWidth();
// h = ofGetHeight();
w = 320 ;
h = 240;
vid.initGrabber(w,h,true);
divider=22;
pixelW=w/divider;
pixelH=w/divider;
brightnessVal=2;

}

//--------------------------------------------------------------
void ofApp::update(){
ofSetWindowTitle(ofToString(ofGetFrameRate()));
vid.update();

}

//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(0,0,0);
ofSetColor(255,255,255);

for (int y=0; y<h; y+=pixelH) {
    for (int x=0; x<w; x+=pixelW) {
        
        //get pixel color
        int i = (y*w+x)*3;
        int r = vid.getPixels()[i+0];
        int g = vid.getPixels()[i+1];
        int b = vid.getPixels()[i+2];
        
        //calculate brightness
        float br = (r+b+g) / 765.0*brightnessVal;
        //float br = (r) / 765.0*brightnessVal;

        
        //use HSB color
        ofSetColor(255*br);
        //ofSetColor(ofColor::fromHex(br*255,255));

        
        //calculate sine and cosine of brightness
        float co = cos(br*TWO_PI);
        float si = sin(br*TWO_PI);
        
        //draw rotated line based on brightness
        //ofLine(x-5*co, y-5*si, x+5*co, y+5*si);
        ofRect(x, y, pixelW, pixelH);
    }
}

}

I think I sorted that out like this

        if(br<0.5 && br> 0){
            ofSetColor(0);

        }
        else {
            ofSetColor(255);


        }

still working on this… now I have to send this to Arduino… :sunny: