FSR按下以增加显示器上的变量

时间:2016-09-03 17:25:51

标签: arduino led

更新:所以我收到错误:“使用此代码在'fsrAnalogPin'之前预期的初始化程序”。有人可以帮我解决这个问题吗?

// 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
#define PULLUP true              //use the AVR's internal pullup resistor
#define INVERT true              //low level means fsr pressed
#define DEBOUNCE_TIME 50         //milliseconds
// 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 loop(){

  Serial.begin(9600);

  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');

{
const int fsr_pin = A4;             //connect fsr from this pin to ground
int read fsrAnalogPin = 4;
    fsr_pin.read(); 
    if( fsr_pin.wasPressed() ){
        counter = counter + 1
        matrix.setTextColor( matrix.Color333(0,7,7) );
        matrix.print( counter )
    }
}

  // whew!
}

void loop() {
  // do nothing
}

如果有人可以帮我处理我的代码,我将非常感激。我要做的是:使用一个力敏电阻,我想用一个arduino计算FSR上给定的压力,然后在LED矩阵上显示每个抽头。换句话说,我手上有一个带有FSR的手套,我想计算“拳头颠簸”然后显示在32x32 Adafruit LED矩阵上。

以下是我希望它的样子: https://drive.google.com/file/d/0B4kq-ADrtz4mSzNWUTJoNGlBSU0/view?usp=sharing

这只是底部的静态数字。我需要帮助制作代码将计数变量连接到FSR“颠簸”。它可能很简单,但我对此完全是新手,因此需要学习很多东西。所以任何帮助都表示赞赏

以下是我的代码:

// 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
#define FSR_PIN A4               //connect fsr from this pin to ground
#define PULLUP true              //use the AVR's internal pullup resistor
#define INVERT true              //low level means fsr pressed
#define DEBOUNCE_TIME 50         //milliseconds
// 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() {

  Serial.begin(9600);

  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');

  void loop(void)
{
   fsr.read();
   if (fsr.wasPressed()) {
       Serial.print(++counter, DEC);
       Serial.println(" steps");
   }

  matrix.setTextColor(matrix.Color333(0,7,7)); 
  matrix.print("29291");


  // whew!
}

void loop() {
  // do nothing
}

1 个答案:

答案 0 :(得分:0)

首先,您需要从loop()删除setup()方法。

void loop()方法中,进行以下更改可以使事情正常进行。

void loop(){
    fsr.read(); 
    if( fsr.wasPressed() ){
        counter = counter + 1
        matrix.setTextColor( matrix.Color333(0,7,7) );
        matrix.print( counter )
    }
}

修改

// 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
#define PULLUP true              //use the AVR's internal pullup resistor
#define INVERT true              //low level means fsr pressed
#define DEBOUNCE_TIME 50         //milliseconds
// 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(){

  Serial.begin(9600);

  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');
}

void loop(){
    const int fsr_pin = A4;             //connect fsr from this pin to ground
    int read fsrAnalogPin = 4;
    fsr_pin.read(); 
    if( fsr_pin.wasPressed() ){
        counter = counter + 1
        matrix.setTextColor( matrix.Color333(0,7,7) );
        matrix.print( counter )
    }
}

我还建议遵循适当的缩进。这将使您的代码可读。如果你修改你的Arduino编程也会很棒。概念