Go Down

Topic: Converting ints into byte array  (Read 108 times) previous topic - next topic

DenGov

I'm working on a project were i want integers to go into a byte array.
I'm using a MAX7219 led matrix to display these integers.




Code: [Select]

#include "LedControl.h"

LedControl lc = LedControl(12, 11, 10, 1);
const int buttonPin = 2;

const int delayTime = 400;
int buttonState = 0;


float v1 = 1;
float v2 = 1;
float v3 = 1;

int row1[] ={0,0,0,0,1,1,0,0};

byte ledM[] =
{
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B  v1 v2 v3,
  B00000000
};

void pLedM()
{
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, ledM[i]);
  }
}

void setup() {
  lc.shutdown(0, false);
  lc.setIntensity(0, 2);
  lc.clearDisplay(0);
  pinMode(buttonPin, INPUT);
}

void loop() {

 

/*
  if (buttonState == HIGH) {
    pir1 = 1;
  } else {
    pir1 = 0;
  }
*/

int row1[2] = {1};
 
   for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, ledM[i]);
  }
}


now i want so every variable has to be responsible for one led on the matrix.

sterretje

Your requirements are not clear; please try to explain again. I see a byte array but I don't really see which integer you're talking about.

Further

Code: [Select]

byte ledM[] =
{
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B  v1 v2 v3, <----------------- What is this
  B00000000
};

Please explain the line above; what do you want to achieve?

Code: [Select]

void loop()
{
  ...
  ...

  int row1[2] = {1};


This more than likely does not do what you think it does. It creates a new variable row1 with 2 elements and initializes the first element with the value 1. This new variable hides your global row1 array.

If you want to assign a value to the third element in the global row1 array, use
Code: [Select]

void loop()
{
  ...
  ...

  row1[2] = 1;

If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up