Related
I receive data from an external device in decimal values, that I need to convert in ascii and then push it in a list
data example:
#onData: 1,3,200,
78,69,84,71,69,65,82,45,71,117,101,115,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
70,114,105,103,111,109,97,116,45,49,50,51,52,53,54,55,56,45,87,73,70,73,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
77,73,67,82,79,45,83,89,83,84,69,77,83,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
77,73,67,82,79,45,83,89,83,84,69,77,83,45,71,85,69,83,84,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
77,73,67,82,79,45,83,89,83,84,69,77,83,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,123
The first 3 elements of #onData need to be ignored and the last 2 elements as well.
In ascii it would be:
NETGEAR-Guest
Frigomat-12345678-WIFI
MICRO-SYSTEMS
MICRO-SYSTEMS-GUEST
MICRO-SYSTEMS
I have a method to convert:
arrayBuffer2str(buf) {
var str = "";
var ui8 = new Uint8Array(buf);
for (var i = 0; i < ui8.length; i++) {
str = str + String.fromCharCode(ui8[i]);
}
return str;
}
I would need to get rid of the zeros and then push it in an array of strings:
this.wifiNetworks.push("Network-1");
Thank you
If you want to extract the buffer between two zeros and isolate the significant response, try this
let prevVal;
let phrase= [];
for (let i=0; i<array.length; i++) {
let val = array[i];
if (val == 0 && prevVal != 0) {
// end of response
process(phrase);
}
if (prevVal == 0 && val != 0) {
// start new response
phrase= [];
}
phrase.push(val);
prevVal = val;
}
function process(phrase) {
// TODO Process your phrase here and remove the inner zeros
}
Also, consider removing your zeros using the .filter function
Try this,
Assuming that we are getting the input as an array.
const inputArray = [1, 3, 200,
78, 69, 84, 71, 69, 65, 82, 45, 71, 117, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
70, 114, 105, 103, 111, 109, 97, 116, 45, 49, 50, 51, 52, 53, 54, 55, 56, 45, 87, 73, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77, 73, 67, 82, 79, 45, 83, 89, 83, 84, 69, 77, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77, 73, 67, 82, 79, 45, 83, 89, 83, 84, 69, 77, 83, 45, 71, 85, 69, 83, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77, 73, 67, 82, 79, 45, 83, 89, 83, 84, 69, 77, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 123];
const resultArray = [];
let stringIndex = 0;
for (i = 3; i <= inputArray.length - 3; i++) {
if (inputArray[i] !== 0) {
resultArray[stringIndex] = resultArray[stringIndex]
? resultArray[stringIndex].concat(String.fromCharCode(inputArray[i]))
: ''.concat(String.fromCharCode(inputArray[i]));
} else if (inputArray[i - 1] !== 0) {
stringIndex = stringIndex + 1
}
}
console.log(resultArray);
// Add code to push the result to server,
The output would be
[ 'NETGEAR-Guest', 'Frigomat-12345678-WIFI', 'MICRO-SYSTEMS',
'MICRO-SYSTEMS-GUEST', 'MICRO-SYSTEMS' ]
I would like to know how to reshape a 2-D linearized Array in Scala without loops, i.e. by using functional programming.
Assume a 2-D Array of 6x12 = 72 elements. What I need is to resize this Array so that it has 8x16 = 128 elements, assuming that the new elements are initialized to zero.
This is how I do it with loops:
val a = (1 to 72).toArray
a: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72)
scala> val h = 6
h: Int = 6
scala> val w = 12
w: Int = 12
scala> val H = 8
H: Int = 8
scala> val W = 16
W: Int = 16
scala> val b = Array.ofDim[Int](H * W)
b: Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for (i <- 0 until h)
for (j <- 0 until w)
b(i * W + j) = a(i * w + j)
b: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 0, 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 0, 0, 0, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 0, 0, 0, 0, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 0, 0, 0, 0, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 0, 0, 0, 0, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
The question is: how to do this by using functional programming?
Thank you very much!
a.grouped(w).map(_.padTo(W, 0)).padTo(H, Array.fill(W)(0)).flatten.toArray
Result (and string copied from your code, for comparison):
result : Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 0, 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 0, 0, 0, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 0, 0, 0, 0, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 0, 0, 0, 0, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 0, 0, 0, 0, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
b: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 0, 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 0, 0, 0, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 0, 0, 0, 0, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 0, 0, 0, 0, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 0, 0, 0, 0, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
I have been playing around with ray-casting and decided to use 3D arrays to make levels, However TCC spits out this:
M_MAIN.C:19: error: index too large
Is there a limit to how large an array can be?
Code:
#define MAP_01_WIDTH 8
#define MAP_01_HEIGHT 8
#define MAP_01_DEPTH 8
#define MAP_01_PLAYER_START_X 2
#define MAP_01_PLAYER_START_Y 2
#define MAP_01_PLAYER_START_Z 2
char MAP_01[MAP_01_WIDTH][MAP_01_DEPTH][MAP_01_HEIGHT] =
{
{ {1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {2, 0, 3, 0, 0, 4, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 0, 0, 0, 0, 0, 0, 1}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 0, 0, 2}, {1, 0, 0, 0, 0, 0, 0, 1} },
{ {1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1} }
};
You define the array with size 8x8x8 but initializing it with 9x8x8 elements. Fix the size with:
#define MAP_01_WIDTH 9
Or better yet, let the compiler calculate that:
char MAP_01[][MAP_01_DEPTH][MAP_01_HEIGHT] = {...};
I have a bidimensional array of struct that I defined and I want to get a value in a struct which itself is contained in an array.
I have tried to do the same kind of code in bare C and it seems to work while or Arudino IDE it doesn't (code isn't the exact same but it's generally the same thing).
Look at the example below, I am printing an arbitrary value taken out of my array of struct over serial and the only input I get on the Serial Monitor is a suit of 'ΓΏ' which from what I've seen on the internet means that the serial buffer is empty.
Does anything look wrong to you within the code below? (look at the end to see the relevant code)
#include <Wire.h>
typedef struct {
char nom[17]; // wanted number +1 for terminaison
byte cor1[2]; // correspondance
byte cor2[2];
byte cor3[2];
byte cor4[2];
byte i2c;
byte led;
} Station;
Station lignes[14][15] = {{
{"Champs Elysees", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11101111},
{"Concorde", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B10111111},
{"Tuileries", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11101111},
{"Palais Royal", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B10111111},
{"Louvre Rivoli", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B11101111},
{"Chatelet", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B10111111},
{"Hotel de Ville", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11101111},
{"St-Paul", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11011111},
{"Bastille", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111},
{"Ledru-Rollin", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111},
{"Faidherbe", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011}
},
{
},
{
{"Saint-Lazare", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11111110},
{"Havre Caumartin", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11111110},
{"Opera", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B11110111},
{"Quatre Septembre", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B11111101},
{"Bourse", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11011111},
{"Sentier", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11110111},
{"R. Sebastopol", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11111101},
{"Arts et Metiers", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B01111111},
{"Temple", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B10111111},
{"Republique", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11110111}
},
{
{"S. Saint-Denis", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11011111},
{"R. Sebastopol", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11111101},
{"Etienne Marcel", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11111011},
{"Les Halles", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B10111111},
{"Chatelet", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B10111111},
{"Cite", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B01111111},
{"St-Michel", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111110},
{"Odeon", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111101},
{"St-Germain", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B10111111},
{"Saint-Sulpice", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B10111111},
{"St-Placide", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B01111111},
{"Montparnasse", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111},
{"Vavin", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B01111111},
{"Raspail", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011},
{"Denfert", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111}
},
{
{"J. Bonsergent", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11111011},
{"Republique", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11110111},
{"Oberkampf", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B01111111},
{"Richard Lenoir", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111110},
{"Breguet Sabin", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111101},
{"Bastille", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111},
{"Quai de la Rapee", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111101},
{"Gare Austerlitz", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111},
{"Saint Marcel", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B10111111},
{"Campo Formio", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11011111},
},
{
{"Pasteur", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11011111},
{"Montparnasse", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111},
{"Edgar Quinet", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B10111111},
{"Raspail", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011},
{"Denfert", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111}
},
{
{"Le Peletier", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11110111},
{"La Fayette", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11111011},
{"Opera", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B11110111},
{"Pyramides", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B01111111},
{"Palais Royal", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B10111111},
{"Pont Neuf", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B11011111},
{"Chatelet", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B10111111},
{"Pont Marie", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111101},
{"Sully Morland", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111110},
{"Jussieu", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011},
{"Place Monge", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111},
{"C. Daubenton", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011},
{"Les Gobelins", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B10111111},
},
{
{"Invalides", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B11110111},
{"Concorde", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B10111111},
{"Madeleine", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11011111},
{"Opera", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B11110111},
{"Richelieu Drouot", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11111101},
{"Gds Boulevards", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B11111011},
{"Bonne Nouvelle", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11111110},
{"S. Saint-Denis", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11011111},
{"Republique", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11110111},
{"F. du Calvaire", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11101111},
{"St-S. Froissart", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B01111111},
{"Chemin Vert", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B01111111},
{"Bastille", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111},
{"Ledru Rollin", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111},
{"Faidherbe", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011}
},
{
{"Saint Philippe", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11110111},
{"Miromesnil", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11111011},
{"Saint-Augustin", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11111101},
{"Havre Caumartin", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11111110},
{"La Fayette", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11111011},
{"Richelieu Drouot", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100110, B11111101},
{"Gds Boulevards", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100010, B11111011},
{"Bonne Nouvelle", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11111110},
{"S. Saint-Denis", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11011111},
{"Republique", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11110111},
{"Oberkampf", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B01111111}
},
{
{"Duroc", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111},
{"Vanneau", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B01111111},
{"Sevres Babylone", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011},
{"Mabillon", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B01111111},
{"Odeon", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111101},
{"La Sorbonne", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111101},
{"Maubert", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11011111},
{"Cardinal Lemoine", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B01111111},
{"Jussieu", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011},
{"Gare Austerlitz", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111}
},
{
{"Chatelet", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B10111111},
{"Hotel de Ville", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11101111},
{"Rambuteau", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B11011111},
{"Arts et Metiers", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B01111111},
{"Republique", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11110111},
{"Goncourt", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11111101},
{"Belleville", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100000, B11111110}
},
{
{"Saint-Lazare", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11111110},
{"Madeleine", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11011111},
{"Concorde", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B10111111},
{"Assemblee", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B11111011},
{"Solferino", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B11111110},
{"Rue du Bac", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B11101111},
{"Sevres Babylone", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111011},
{"Rennes", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111},
{"N-D. Des-Champs", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11011111},
{"Montparnasse", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111},
{"Falguiere", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B10111111},
{"Pasteur", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11011111},
{"Volontaires", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111}
},
{
{"Saint-Lazare", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11111110},
{"Miromesnil", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11111011},
{"Champs Elysees", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11101111},
{"Invalides", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B11110111},
{"Varenne", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B11111101},
{"St-Fr. Xavier", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100101, B11011111},
{"Duroc", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111},
{"Montparnasse", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11101111},
{"Gaite", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11111110}
},
{
{"Saint-Lazare", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11111110},
{"Madeleine", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B11011111},
{"Pyramides", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100001, B01111111},
{"Chatelet", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0100100, B10111111},
{"Gare de Lyon", {0, 0}, {0, 0}, {0, 0}, {0, 0}, B0111000, B11110111}
}};
void setup() {
// Wire.begin();
Serial.begin(9600);
}
void loop(){
// for (int j=0; j<16; j++) {
byte a = lignes[0][0].i2c;
Serial.write(a);
/* for (int i=0; i<14; i++) {
Serial.print(lignes[0][i].i2c, BIN);
Serial.print(lignes[0][i].led, BIN);
Serial.println(" ");
/* Wire.beginTransmission(lignes[0][i].i2c); // PCF8574P GGG
Wire.write(lignes[0][i].led);
Wire.endTransmission();
delay(10);*/
// }
// }
}
Thanks a lot in advance for your help, I already spent a lot of time on this...
In your given example, you are writing "lignes[0][0].i2c" which is B0100001. That is an ASCII code for space. Try validating your serial conection with a simple
Serial.Write("Hello World");
If that passes then try printing an actual string, for example,
Serial.Write(&lignes[0][0].nom)
Apparently, it was caused by a memory overflow (thanks to Arduino IDE for NOT pointing that).
The Arduino IDE says 36kB available but that's Flash memory, one has to account SRAM.
This is worked-around by using PROGMEM.
cf. http://arduino.cc/en/Tutorial/Memory
http://www.arduino.cc/en/Reference/PROGMEM
Also be careful, you have to use special functions for extracting and using value stored with PROGMEM.
There are already a few of those threads on here, but none of them actually answer my problem.
In my header I have:
struct table_val
{
char res;
char carry;
};
typedef struct table_val TABLE_VAL;
and in my source file I try to create this static array of structs:
struct TABLE_VAL add_table[] = {
{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0},
{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1},
{2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1},
{3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1},
{4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1},
{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1},
{6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1},
{7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1},
{8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1},
{9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, {8, 1}
};
Compiling this leads to the error in the title. Am I not allowed to create an array in that manner? If not, is there a short version, than initializing every struct after creation?
Use
TABLE_VAL add_table[]
or
struct table_val add_table[]
and not
struct TABLE_VAL add_table[]
When you do:
typedef struct table_val TABLE_VAL;
you are creating a type alias named TABLE_VAL for the type struct table_val.