Hello, if someone can help me with my code I would be very grateful. What I'm trying to do is: Using a force-sensitive resistor, I want to count a given amount of pressure on the FSR with an arduino, that then displays each tap on an LED matrix. In other words, I have a glove with an FSR on it, and I want to count "fist bumps" that then display on an 32x32 Adafruit LED matrix.
Here's an example of what I want it to look like:
That is just a static number on the bottom though. I need help making the code to connect a counting variable to the FSR "bumps." It's probably pretty simple but I'm entirely new to this so it's a lot to learn. So any help is appreciated
Here is what I have for code:
// testshapes demo for Adafruit RGBmatrixPanel library.
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 32x32 RGB LED matrix:
// http://www.adafruit.com/products/607
// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
// for Adafruit Industries.
// BSD license, all text above must be included in any redistribution.
#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
// If your 32x32 matrix has the SINGLE HEADER input,
// use this pinout:
#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
// If your matrix has the DOUBLE HEADER input, use:
//#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
//#define LAT 9
//#define OE 10
//#define A A3
//#define B A2
//#define C A1
//#define D A0
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);
void setup() {
matrix.begin();
// draw a pixel in solid white
matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
delay(500);
// fix the screen with green
matrix.fillRect(0, 0, 32, 32, matrix.Color333(0, 7, 0));
delay(500);
// draw a box in yellow
matrix.drawRect(0, 0, 32, 32, matrix.Color333(7, 7, 0));
delay(500);
// draw an 'X' in red
matrix.drawLine(0, 0, 31, 31, matrix.Color333(7, 0, 0));
matrix.drawLine(31, 0, 0, 31, matrix.Color333(7, 0, 0));
delay(500);
// draw a blue circle
matrix.drawCircle(10, 10, 10, matrix.Color333(0, 0, 7));
delay(500);
// fill a violet circle
matrix.fillCircle(21, 21, 10, matrix.Color333(7, 0, 7));
delay(500);
// fill the screen with 'black'
matrix.fillScreen(matrix.Color333(0, 0, 0));
// draw some text!
matrix.setCursor(1, 0); // start at top left, with one pixel of spacing
matrix.setTextSize(1); // size 1 == 8 pixels high
matrix.setTextWrap(false); // Don't wrap at end of line - will do ourselves
matrix.setTextColor(matrix.Color333(7,7,7));
matrix.println("FIST");
matrix.println(" BUMP");
// print each letter with a rainbow color
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print('C');
matrix.setTextColor(matrix.Color333(7,4,0));
matrix.print('O');
matrix.setTextColor(matrix.Color333(7,7,0));
matrix.print('U');
matrix.setTextColor(matrix.Color333(4,7,0));
matrix.print('N');
matrix.setTextColor(matrix.Color333(0,7,0));
matrix.println('T');
matrix.setTextColor(matrix.Color333(0,7,7));
matrix.print('1');
matrix.setTextColor(matrix.Color333(0,4,7));
matrix.print('0');
matrix.setTextColor(matrix.Color333(0,0,7));
matrix.print('2');
matrix.setTextColor(matrix.Color333(4,0,7));
matrix.print("0");
matrix.setTextColor(matrix.Color333(7,0,4));
matrix.print("9");
// whew!
}
void loop() {
// do nothing
}
and this for the FSR:
/* FSR LCD display sketch, based on "FSR simple testing sketch" .
Connect one end of FSR to power, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Potentiometer is connected to LCD and power/GND
LCD connected following scematic in Sparkfun Inventor Kit circuit #15
FSR is homemade, using conductive foam and two wires
*/
int fsrPin = 0; // the FSR and 10K pulldown are connected to a0
int fsrReading; // the analog reading from the FSR resistor divider
int fsrMin = 1023; // minimum sensor value
int fsrMax = 0; // maximum sensor value
#include <LiquidCrystal.h> //call the LCD library
LiquidCrystal lcd(12,11,5,4,3,2); //LCD connected to these pins
void setup(void) {
lcd.begin(16, 2); //Turn on the LCD
lcd.clear();
// calibrate during the first five seconds DON'T FORGET TO PUSH THE FSR HARD!!!
while (millis() < 5000) {
fsrReading = analogRead(fsrPin);
// record the maximum sensor value
if (fsrReading > fsrMax) {
fsrMax = fsrReading;
}
// record the minimum sensor value
if (fsrReading < fsrMin) {
fsrMin = fsrReading;
}
}
}
void loop(void) {
fsrReading = analogRead(fsrPin);
fsrReading = map(fsrReading, fsrMin, fsrMax, 0.0, 10.0); //FSR pressure mapped on a scale of 1-10.
// Scale could be adjusted for more accurate force output when calibration is more controlled.
fsrReading = constrain(fsrReading, 0.0, 10.0); // no readings above or below the 0-10 scale
Ignore the LCD part of the second code, as I am using an LED matrix. This is part of what I need help with!
Thanks!