small code problem 16x32

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
13andrew
 
Posts: 13
Joined: Thu Dec 26, 2013 1:11 pm

small code problem 16x32

Post by 13andrew »

ok so my long testshapes() isnt working here is code

Code: Select all

#include <avr/pgmspace.h>
#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>

int buttonApin = 8;
int doShowPlasma = 0;
int doShowMessage = 0;
int dontshowanything = 0;
int totestshapes = 0;
int buttonBpin = 9;
int buttonCpin = 10;
int buttonDpin = 11;
#define CLK 50  // MUST be on PORTB!
#define LAT A3
#define OE  51
#define A   A0
#define B   A1
#define C   A2

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
static const int8_t PROGMEM sinetab[256] = {
     0,   2,   5,   8,  11,  15,  18,  21,
    24,  27,  30,  33,  36,  39,  42,  45,
    48,  51,  54,  56,  59,  62,  65,  67,
    70,  72,  75,  77,  80,  82,  85,  87,
    89,  91,  93,  96,  98, 100, 101, 103,
   105, 107, 108, 110, 111, 113, 114, 116,
   117, 118, 119, 120, 121, 122, 123, 123,
   124, 125, 125, 126, 126, 126, 126, 126,
   127, 126, 126, 126, 126, 126, 125, 125,
   124, 123, 123, 122, 121, 120, 119, 118,
   117, 116, 114, 113, 111, 110, 108, 107,
   105, 103, 101, 100,  98,  96,  93,  91,
    89,  87,  85,  82,  80,  77,  75,  72,
    70,  67,  65,  62,  59,  56,  54,  51,
    48,  45,  42,  39,  36,  33,  30,  27,
    24,  21,  18,  15,  11,   8,   5,   2,
     0,  -3,  -6,  -9, -12, -16, -19, -22,
   -25, -28, -31, -34, -37, -40, -43, -46,
   -49, -52, -55, -57, -60, -63, -66, -68,
   -71, -73, -76, -78, -81, -83, -86, -88,
   -90, -92, -94, -97, -99,-101,-102,-104,
  -106,-108,-109,-111,-112,-114,-115,-117,
  -118,-119,-120,-121,-122,-123,-124,-124,
  -125,-126,-126,-127,-127,-127,-127,-127,
  -128,-127,-127,-127,-127,-127,-126,-126,
  -125,-124,-124,-123,-122,-121,-120,-119,
  -118,-117,-115,-114,-112,-111,-109,-108,
  -106,-104,-102,-101, -99, -97, -94, -92,
   -90, -88, -86, -83, -81, -78, -76, -73,
   -71, -68, -66, -63, -60, -57, -55, -52,
   -49, -46, -43, -40, -37, -34, -31, -28,
   -25, -22, -19, -16, -12,  -9,  -6,  -3
};

char   str[]   = "How-To-Speech";
int    textX   = matrix.width(),
       textMin = sizeof(str) * -10;
long   hue     = 1;
long   color   = 0;
void setup() {
  pinMode(buttonApin, INPUT_PULLUP);  
  pinMode(buttonBpin, INPUT_PULLUP);
  pinMode(buttonCpin, INPUT_PULLUP);
  pinMode(buttonDpin, INPUT_PULLUP);
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setTextSize(2.3);
}
const float radius1  = 65.2, radius2  = 92.0, radius3  = 163.2, radius4  = 176.8,
            centerx1 = 64.4, centerx2 = 46.4, centerx3 =  93.6, centerx4 =  16.4, 
            centery1 = 34.8, centery2 = 26.0, centery3 =  56.0, centery4 = -11.6;
float       angle1   =  0.0, angle2   =  0.0, angle3   =   0.0, angle4   =   0.0;
long        hueShift =  1;
void loop() 
{
  if (digitalRead(buttonApin) == LOW)
  {
    doShowMessage = true;
    doShowPlasma = false;
  }
  if (digitalRead(buttonBpin) == LOW)
  {
    doShowPlasma = true;
    doShowMessage = false;
  }

  if (doShowMessage)
    showMessage();

  if (doShowPlasma)
    showPlasma(); }
long showMessage() {
  byte i;
  matrix.fillScreen(5);
  matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  matrix.setCursor(textX, 1);
  matrix.print(str);
  if((--textX) < textMin) textX = matrix.width();
  hue   += 50;
  color += 50;
  matrix.swapBuffers(true);
    if (digitalRead(buttonApin) == LOW)
  {
    doShowMessage = true;
    doShowPlasma = false;
    dontshowanything = false;
    totestshapes = false;
  }
  if (digitalRead(buttonBpin) == LOW)
  {
    doShowPlasma = true;
    doShowMessage = false;
    dontshowanything = false;
    totestshapes = false;
  }
  if (digitalRead(buttonCpin) == LOW)
  {
    dontshowanything = true;
    doShowPlasma = false;
    doShowMessage = false;
    totestshapes = false;
  }
  if (digitalRead(buttonDpin) == LOW)
  {
    totestshapes = true;
    dontshowanything = false;
    doShowPlasma = false;
    doShowMessage = false;
  }
  if (doShowMessage)
    showMessage();

  if (doShowPlasma)
    showPlasma();
  
  if (dontshowanything)
    shownothing();
  if (totestshapes)
    testshapes(); 
}
long showPlasma() 
{
  int           x1, x2, x3, x4, y1, y2, y3, y4, sx1, sx2, sx3, sx4;
  unsigned char x, y;
  long          value;

  sx1 = (int)(tan(angle1) * radius1 + centerx1);
  sx2 = (int)(tan(angle2) * radius2 + centerx2);
  sx3 = (int)(tan(angle3) * radius3 + centerx3);
  sx4 = (int)(tan(angle4) * radius4 + centerx4);
  y1  = (int)(tan(angle1) * radius1 + centery1);
  y2  = (int)(tan(angle2) * radius2 + centery2);
  y3  = (int)(tan(angle3) * radius3 + centery3);
  y4  = (int)(tan(angle4) * radius4 + centery4);

  for(y=0; y<matrix.height(); y++) {
    x1 = sx1; x2 = sx2; x3 = sx3; x4 = sx4;
    for(x=0; x<matrix.width(); x++) {
      value = hueShift
        + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x1 * x1 + y1 * y1) >> 5))
        + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x2 * x2 + y2 * y2) >> 5))
        + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x3 * x3 + y3 * y3) >> 7))
        + (int8_t)pgm_read_byte(sinetab + (uint8_t)((x4 * x4 + y4 * y4) >> 7));
      matrix.drawPixel(x, y, matrix.ColorHSV(value * 1, 155, 255, true));
      x1--; x2--; x3--; x4--;
    }
    y1--; y2--; y3--; y4--;
  }

  angle1 += .001;
  angle2 -= .001;
  angle3 += .001;
  angle4 -= .001;
  hueShift += 10;

  matrix.swapBuffers(true);
}
long shownothing()
{
 byte i;
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.ColorHSV(color, 255, 255, true));
  matrix.swapBuffers(true);
     if (digitalRead(buttonApin) == LOW)
  {
    doShowMessage = true;
    doShowPlasma = false;
    dontshowanything = false;
    totestshapes = false;
  }
  if (digitalRead(buttonBpin) == LOW)
  {
    doShowPlasma = true;
    doShowMessage = false;
    dontshowanything = false;
    totestshapes = false;
  }
  if (digitalRead(buttonCpin) == LOW)
  {
    dontshowanything = true;
    doShowPlasma = false;
    doShowMessage = false;
    totestshapes = false;
  }
  if (digitalRead(buttonDpin) == LOW)
  {
    totestshapes = true;
    dontshowanything = false;
    doShowPlasma = false;
    doShowMessage = false;
  }
  if (doShowMessage)
    showMessage();

  if (doShowPlasma)
    showPlasma();
  
  if (dontshowanything)
    shownothing();
  if (totestshapes)
    testshapes();
}
long testshapes() 
{
 {
  matrix.fillRect(0, 0, 32, 16, matrix.Color444(0, 0, 0)); 
  matrix.fillRect(0, 0, 32, 16, matrix.Color444(0, 7, 0));
  delay(920);
  matrix.fillRect(2, 0, 32, 16, matrix.Color333(0, 0, 7));
  delay(910);
  matrix.fillRect(4, 0, 32, 16, matrix.Color333(7, 0, 0));
  delay(900);
  matrix.fillRect(6, 0, 32, 16, matrix.Color333(7, 7, 0));
  delay(890);
  matrix.fillRect(8, 0, 32, 16, matrix.Color333(1, 2, 3));
  delay(880);
  matrix.fillRect(10, 0, 32, 16, matrix.Color333(0, 7, 7));
  delay(860);
  matrix.fillRect(12, 0, 32, 16, matrix.Color444(0, 7, 0));
  delay(850);
  matrix.fillRect(14, 0, 32, 16, matrix.Color333(0, 0, 7));
  delay(840);
  matrix.fillRect(16, 0, 32, 16, matrix.Color333(7, 0, 0));
  delay(830);
  matrix.fillRect(18, 0, 32, 16, matrix.Color333(7, 1, 0));
  delay(820);
  matrix.fillRect(20, 0, 32, 16, matrix.Color333(1, 0, 3));
  delay(810);
  matrix.fillRect(22, 0, 32, 16, matrix.Color333(0, 0, 7));
  delay(800);
  matrix.fillRect(24, 0, 32, 16, matrix.Color333(2, 2, 6));
  delay(790);
  matrix.fillRect(26, 0, 32, 16, matrix.Color333(2, 4, 1));
  delay(780);
  matrix.fillRect(28, 0, 32, 16, matrix.Color333(4, 3, 2));
  delay(770);
  matrix.fillRect(30, 0, 32, 16, matrix.Color333(6, 0, 2));
  delay(760);
  matrix.fillRect(32, 0, 32, 16, matrix.Color333(1, 0, 0));
  delay(750);
}
     if (digitalRead(buttonApin) == LOW)
  {
    doShowMessage = true;
    doShowPlasma = false;
    dontshowanything = false;
    totestshapes = false;
  }
  if (digitalRead(buttonBpin) == LOW)
  {
    doShowPlasma = true;
    doShowMessage = false;
    dontshowanything = false;
    totestshapes = false;
  }
  if (digitalRead(buttonCpin) == LOW)
  {
    dontshowanything = true;
    doShowPlasma = false;
    doShowMessage = false;
    totestshapes = false;
  }
  if (digitalRead(buttonDpin) == LOW)
  {
    totestshapes = true;
    dontshowanything = false;
    doShowPlasma = false;
    doShowMessage = false;
  }
  if (doShowMessage)
    showMessage();

  if (doShowPlasma)
    showPlasma();
  
  if (dontshowanything)
    shownothing();
  if (totestshapes)
    testshapes();
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: small code problem 16x32

Post by adafruit_support_rick »

What is all that code supposed to be doing? What is testshapes supposed to be doing? What does testshapes not do?
Please provide some background information, and explain the problem.

13andrew
 
Posts: 13
Joined: Thu Dec 26, 2013 1:11 pm

Re: small code problem 16x32

Post by 13andrew »

it overlaps colors across the screen into stripes then resets and runs again, its just freezing the previouse image or not doing anythin g at all right now.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”