I'm using an adafruit 8x8 bicolor LED display && ADXL335
only using X and Y axis
00000000
00000000
00000000
00011000
00011000
00000000
00000000
00000000
I want the 1's to stay in a 2x2 square, when "bishifting"
also i'm trying to make the color of the display change depending on the value of the pot.
I have a "set color" function and some bitshift instructions.
the biColor display examples from adafruit are poorly commented in my opinion.
this code is a rough draft.... I would appreciate some guidence and/or insite/direction.
I'm also ok with Paying a tip via paypal for a working example code of what i'm trying to achieve.
If more info is needed please comment.
/***************************************************
This is a library for our I2C LED Backpacks
Designed specifically to work with the Adafruit LED Matrix backpacks
----> http://www.adafruit.com/products/872
----> http://www.adafruit.com/products/871
----> http://www.adafruit.com/products/870
These displays use I2C to communicate, 2 pins are required to
interface. There are multiple selectable I2C addresses. For backpacks
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
with 3 Address Select pins: 0x70 thru 0x77
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
//Pins
int X_Axis = A0;
int Y_Axis = A2;
int button = 2;
//Constants
//Variables
long X_COLOR;
long Y_COLOR;
int X_Now;
int X_Then;
int X_Val;
int Y_Now;
int Y_Then;
int Y_Val;
Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
void setup() {
Serial.begin(9600);
static const uint8_t PROGMEM
seven_bmp[] = // 7
{ B11111110,
B11111110,
B00001110,
B00011100,
B00111000,
B01110000,
B11100000,
B11000000
},
six_bmp[] = // 6
{ B00111110,
B01100011,
B11000000,
B11111110,
B11000011,
B11000011,
B11111111,
B01111110
};
matrix.begin(0x70); // pass in the address
matrix.clear();
matrix.drawBitmap(0, 0, seven_bmp, 8, 8, LED_YELLOW);
matrix.writeDisplay();
delay(750);
matrix.clear();
matrix.drawBitmap(0, 0, six_bmp, 8, 8, LED_YELLOW);
matrix.writeDisplay();
delay(750);
CheckSensor();
}
uint8_t
bmp[] =
{ B00000000,
B00000000,
B00000000,
B00011000,
B00011000,
B00000000,
B00000000,
B00000000
};
void loop() {
X_Now = analogRead(X_Axis);
Y_Now = analogRead(Y_Axis);
ColorSet();
if (X_Now - X_Then > 57) {
//bitshift Left
X_Then = X_Now;
}
if (X_Now - X_Then < 57) {
//bitshift Right
X_Then = X_Now;
}
if (Y_Now - Y_Then > 57) {
//bitshift Left "up"
Y_Then = Y_Now;
}
if (X_Now - X_Then < 57) {
//bitshift Right "down"
Y_Then = Y_Now;
}
Display();
}
void Display() {
matrix.clear();
matrix.drawBitmap(0, 0, bmp, 8, 8, LED_GREEN); // LED_GREEN
matrix.writeDisplay();
delay(50);
}
void CheckSensor() {
X_Now = analogRead(X_Axis);
Y_Now = analogRead(Y_Axis);
Serial.print(X_Now);
Serial.println(Y_Now);
Serial.println(" ");
if (((X_Now > 500) && ( X_Now < 520)) && (( Y_Now > 500) && (Y_Now < 520))) {
X_Val = X_Now;
Y_Val = Y_Now;
X_Then = X_Val;
Y_Then = Y_Val;
loop();
}
else {
matrix.clear();
matrix.drawRect(0, 0, 8, 8, LED_RED);
matrix.fillRect(2, 2, 4, 4, LED_GREEN);
matrix.writeDisplay(); // write the changes we just made to the display
delay(1000);
setup();
}
}
void ColorSet() {
X_Now = analogRead(X_Axis);
Y_Now = analogRead(Y_Axis);
// Set Green
if ((X_Now < 510) && ( X_Now > 514)) {
X_COLOR = LED_GREEN;
}
if (( Y_Now < 510) && (Y_Now > 514)) {
Y_COLOR = LED_GREEN;
}
// Set Yellow
if (((X_Now < 338 ) && ( X_Now > 342)) || (( X_Now < 680) && (X_Now > 684))) {
X_COLOR = LED_YELLOW;
}
if (((Y_Now < 338 ) && ( Y_Now > 342)) || (( Y_Now < 680) && (Y_Now > 684))) {
Y_COLOR = LED_YELLOW;
}
// Set Red
if (((X_Now < 168 ) && ( X_Now > 172)) || (( X_Now < 850) && (X_Now > 854))) {
X_COLOR = LED_RED;
}
if (((Y_Now < 168 ) && ( Y_Now > 172)) || (( Y_Now < 850) && (Y_Now > 854))) {
Y_COLOR = LED_RED;
}
X_Then = X_Now;
Y_Then = Y_Now;
}