Skip to content
Snippets Groups Projects
Commit 250cbe90 authored by William Fish's avatar William Fish
Browse files

updating LEDS

parent e2c5239c
Branches
Tags
No related merge requests found
......@@ -4,7 +4,7 @@
#endif
#define PIN 6
#define stripLength 30
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
......@@ -13,7 +13,7 @@
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, 6, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(stripLength, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
......@@ -38,20 +38,33 @@ void loop() {
int r = 0;
int r2 = 0;
int ledIndex = 0;
char bytes [2];
char bytes [4];
// mouseControl(ledIndex, strip.Color(r,60,60));
if (Serial.available() > 0) {
// read the incoming byte:
Serial.readBytes(bytes,2);
//r2 = Serial.read
// Serial.readBytes(bytes,4);
// mouseControl(0, strip.Color(bytes[0],60,60));
mouseControl(bytes[0],strip.Color(bytes[1],60,60));
// mouseControl(bytes[1],strip.Color(180,60,60));
incomingByte = Serial.read();
for(int i = 0; i <= 30; i++){
if(incomingByte=='a'){
strip.setPixelColor(i, strip.Color(200,0,0));
strip.show();
}else {
strip.setPixelColor(i, strip.Color(5,5,5));
strip.show();
}
}
}
}
void mouseControl(uint32_t i,uint32_t c){
strip.setPixelColor(i, c);
strip.show();
}
......
......@@ -6,7 +6,7 @@ void ofApp::setup(){
bSendSerialMessage = false;
ofBackground(255);
ofSetLogLevel(OF_LOG_VERBOSE);
//ofSetLogLevel(OF_LOG_VERBOSE);
font.load("DIN.otf", 64);
......@@ -23,7 +23,7 @@ void ofApp::setup(){
readTime = 0;
memset(bytesReadString, 0, 4);
//ofDrawRectangle(0, 0, 200, 200);
......@@ -38,14 +38,17 @@ void ofApp::update(){
if (bSendSerialMessage){
//unsigned char array[2] = { ofMap(mouseX, 0, ofGetWidth(), 0, 200) , ofMap(mouseY, 0, ofGetHeight(), 0, 200) };
array[1] = ofMap(mouseX, 0, ofGetWidth(), 0, 200);
serial.writeBytes(&array[0],2);
//unsigned char array[3] = { ofMap(mouseX, 0, ofGetWidth(), 0, 200) , ofMap(mouseY, 0, ofGetHeight(), 0, 200), greenIncrease };
//array[2] = ofMap(mouseX, 0, ofGetWidth(), 0, 200);
//array[0] = 5;
//serial.writeByte('a');
//serial.writeByte
bSendSerialMessage = false;
//serial.writeBytes(&array[0], 3);
}
......@@ -55,23 +58,39 @@ void ofApp::update(){
//--------------------------------------------------------------
void ofApp::draw(){
if (nBytesRead > 0 && ((ofGetElapsedTimef() - readTime) < 0.5f)){
ofSetColor(0);
} else {
ofSetColor(220);
}
string msg;
msg += "click to test serial:\n";
msg += "nBytes read " + ofToString(nBytesRead) + "\n";
msg += "nTimes read " + ofToString(nTimesRead) + "\n";
msg += "read: " + ofToString(bytesReadString) + "\n";
msg += "(at time " + ofToString(readTime, 3) + ")";
font.drawString(msg, 50, 100);
}
//--------------------------------------------------------------
void ofApp::keyPressed (int key){
array[0] = key - 49;
if (key == '1') {
//bSendSerialMessage = true;
serial.writeByte('a');
serial.writeByte('b');
}
else {
serial.writeByte('b');
}
//array[1] = key - 49;
//if (key == 'l') {
// bSendSerialMessage = true;
// /*unsigned char array[3] = { 10 };
//std:cout << "turn leds off" << std::endl;*/
// unsigned char myByte = '225';
// bool byteWasWritten = serial.writeByte(myByte);
// if (!byteWasWritten) {
// std::cout << "byte was not written to serial port" << std::endl;
//}
//else {
// std::cout << "byte written to serial port" << std::endl;
// }
//}
//else {
// unsigned char myByte2 = '200';
//
//}
}
//--------------------------------------------------------------
......@@ -91,7 +110,10 @@ void ofApp::mouseDragged(int x, int y, int button){
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
/*bSendSerialMessage = true;*/
}
//--------------------------------------------------------------
......
......@@ -29,9 +29,9 @@ class ofApp : public ofBaseApp{
int nBytesRead; // how much did we read?
int nTimesRead; // how many times did we read?
float readTime; // when did we last read?
//int greenIncrease = 10;
ofSerial serial;
unsigned char array[2] = { 0,0 };
unsigned char array[3] = { 0,0,0 };
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment