Hello everyone,
is it possible to read a integer variable and cut it into an array[], where only one number is part of the array field?
Like int data= 101; equals Data1[1,0,1] after read by a loop maybe?
Why?
User key in on foil keyboard "101" and "#" which stores "data=101".... Arduino converts to array and
then reads in a loop which the array[i-element] later and blinks at the same pattern (1)on (0)off (1)on.
i have found bitRead(variable, ?PlacetoRead?) but the pattern is bad 
boolean Data1[8]; // = {true, true, false, false, false, true, false, true};
int truth1 = 11000101;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Setup Done");
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < 8; i++) {
if(bitRead(truth1, i)){
Data1[i] = true;
}else{Data1[i] = false;}
}
for (int i = 0; i < 8; i++) {
Serial.print(i);
Serial.print(": ");
Serial.print(Data1[i]);
Serial.print("/ ");
}
Serial.println();
delay(2500);
}
On the serial monitor it give:
0:1# 1:0# 2:1# 3:0# 4:0#5:1#6:0#7:0#
Just index the array backwards with [7-i]. Or else populate it backwards the same way. Or change one of your loop setups to:
for (int i = 7; i >= 0; i--) {
Replace:
int truth1 = 11000101;
with:
int truth1 = 0b11000101;
You were actually assigning the decimal number 11,000,101 to the int (which is actually too large for an int) rather the binary 11000101.
Also, it looks like you want to have the user enter the binary sequence from a keypad, in which case you will get an ASCII "0" and "1" for each key press and not an integer. I would just collect those in a character array and then test bit 0 of each character in order to populate the Boolean array.
now my current problem is to get 11.111.100, or eleven milion... in an boolean array and print it on the standard arduino TFT.h as a ?text? string in 11111100
@ToddL1962 thats a very good idear but i do convert all the button presses into numbers when they come in from my foil keyboard maybe thats a stupid idear?
I go from ASCII to numbers and then choose to store in "A" or "B" variable. Thats was my first idear and i thought it would be easier that way if you look at the case 65: {/Button 'A'/ part.
long digits = 0;
boolean Data1[8];
in Loop i do read the keyboard:
char ch = keypad.getKey();
switch (ch)
{
case 65: {/*Button 'A'*/
if (999>=digits>=1){
tdelay = digits;
digits = 0;
wtft = 1;}
else{digits = 0;}
} break;
case 66: {/*Button 'B'*/
if (999>=digits>=1){
ton = digits;
digits = 0;
wtft = 1;}
else{digits = 0;}
} break;
case 67: { /*Button 'C'*/
Serial.println('#');
for (int i=7;i>=0;i--) {
if (bitRead(digits, i)){
Data1[i] = true;Serial.print(Data1[i]);
}else{
Data1[i] = false;Serial.print(Data1[i]);
}
}
wtft = 1;
} break;
case 35: {/*Button '#' */
Serial.println("In digits: "+digits);
}break;
case 42: {/*Button '*' */
digits = 0;
Serial.println("Clear: "+digits);
}
default:/* Button 0 - 9*/
if ( isdigit(ch) )
{
uint8_t buttonNum = ch - '0'; //ASCII to numbers
digits = ((digits * 10) + buttonNum); //key in as squence
}
}
if (999>=digits>=1)
doesn't do what you think/hope
if (digits>=1 && digits <= 999)
case 65: {/*Button 'A'*/
Just write case 'A':
then you don't need the stupid comment
thank you!
i will edit that in my code but the if statement works somehow i could not store 10 000 in
currently i do write it to the tft display:
String stringDigits=String(digits);
stringDigits.toCharArray(printout,9);
TFTscreen.text(printout,0,60);
now i need to cut with a loop to store in an array :-p
but the if statement works somehow i could not store 10 000 in
Because 10000 is greater than 999, perhaps?