Pages: [1]   Go Down
Author Topic: shield for Arduino Sparkfun DEV-11848  (Read 174 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I bought a shield for Arduino Sparkfun DEV-11848
https://www.sparkfun.com/products/11848

I modified an exemplary and I could get the display of a program number.
In my case 3542 :

Wire.endTransmission();
 i2cSendString("3542");  //Send the four characters to the display

Here is my problem:
I would like to display a variable instead of "3542"
This variable has the following format :

volatile int compt=0; // variable de comptage volatile

How to display the value of the variable compt  instead of 3542 ?

Thank you for your help



Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50154
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How to display the value of the variable compt  instead of 3542 ?
Since you need to define what to display as a a string, you need to convert the value to a string. The itoa() function does just that.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Thank you for the reply.

I have other question s:

Should we add a library to the Arduino software ?

I tried to use the itoa instruction without adding library but I have an error message. Maybe I do not have the correct syntax ?

Thank you
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50154
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Maybe I do not have the correct syntax ?
My crystal ball says you don't.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ahhhh ça fonctionne
Le programme :

Quote
/*

Broches Arduino utilisées
A5 to SCL
A4 to SDA
VIN to PWR
GND to GND

*/

int compt0 = 6931; //déclaration du nombre 6931

#include <Wire.h>

#define DISPLAY_ADDRESS1 0x71 //C'est l'adresse par défaut de la OpenSegment avec les deux jumpers ouverts

void setup()
{
  Wire.begin(); // Connection au bus I2C en tant que maitre

  Wire.beginTransmission(DISPLAY_ADDRESS1); // Débute une transmission sur le bus I2C vers le composant esclave ayant l'adresse indiquée
  Wire.write('v'); // envoie la valeur
  Wire.endTransmission(); // finalise la transmission
}

void loop()
{
  Wire.beginTransmission(DISPLAY_ADDRESS1);
  Wire.write(0x7A); // Brightness control command
  Wire.write(50); // Set brightness level: 0% to 100%
  Wire.endTransmission();
  
  char buffer[4]; // buffer de 4 caractères (Mais ça fonctionne avec 0 et aussi avec un nombre qui a plus de 4 caractères ???)
  
  itoa(compt0,buffer,10); // conversion de compt0 en 4 caractères décimaux
 
  i2cSendString(buffer); //Send the four characters to the display
  
  delay(1000);


}

void i2cSendString(char *toSend) // Envoie les 4 premiers caractères
{
  Wire.beginTransmission(DISPLAY_ADDRESS1); // transmit to device #1
  for(byte x = 0 ; x < 4 ; x++)
    Wire.write(toSend
  • ); //Send a character from the array out over I2C
      Wire.endTransmission(); //Stop I2C transmission
    }

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50154
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure how you expect '6', '9', '3', '1', and NULL to fit in a 4 element array.
I'm not sure what error message you are seeing.
I AM sure that your code doesn't really look like that.
I AM sure that you didn't read the "How to post on this forum" sticky at the top of the forum.
Logged

Pages: [1]   Go Up
Jump to: