extracting a value from an array
hi everyone,
i have problems code.
what want turn on several leds using charlieplexing. thees leds have light according defined number sequence (which called number).
i have created function turn on led given name (for example led1, led2...) array of 2 elements (because of charlieplexing).
i have defined number should control leds int (i don't know if correct) , array names of leds (ledlist).
my idea "grab" first element of number (1 in case) , turn on led1 think ledlist[1] , on other numbers (123456654321).
what wrote inside loop attempt i'm quite sure wrong feel free modify it.
thank you
i have problems code.
what want turn on several leds using charlieplexing. thees leds have light according defined number sequence (which called number).
i have created function turn on led given name (for example led1, led2...) array of 2 elements (because of charlieplexing).
i have defined number should control leds int (i don't know if correct) , array names of leds (ledlist).
my idea "grab" first element of number (1 in case) , turn on led1 think ledlist[1] , on other numbers (123456654321).
code: [select]
int ledpins[] = {8,9,10}; // used pins
int pincount = 3; // total number of pins
int timetowait = 500;
//
int led1[] = {10, 9};
int led2 [] = {9,10};
int led3[] = {9, 8};
int led4 [] = {8,9};
int led5[] = {10, 8};
int led6 [] = {8,10};
int ledlist[] = {0, 'led1[]', 'led2[]', 'led3[]', 'led4[]', 'led5[]', 'led6[]'};
string number = "123456654321";
void setup() {
serial.begin(9600);
digitalwrite(4,high); //pin per testare led
}
void loop() {
(int thispin = 0; thispin < number.length(); thispin++){
int mynumber = (int)number[thispin] - 48;
cwriteh((int)(char)ledlist[mynumber]);
delay(timetowait);
cwritel((int)(char)ledlist[mynumber]);
delay(timetowait);
serial.println(ledlist[mynumber]);
delay(timetowait);
}
}
// function charlieplexing and, it's own, works
void cwriteh(int led[]){
(int thispin = 0; thispin < pincount; thispin++) {
pinmode(ledpins[thispin], input);
} //imposta tutti pins come input
pinmode(led[0], output);
digitalwrite(led[0],high);
pinmode(led[1], output);
digitalwrite(led[1],low);
}
void cwritel(int led[]){
pinmode(led[0], input);
}
what wrote inside loop attempt i'm quite sure wrong feel free modify it.
thank you
pinmode() called in setup(). try do:
cwriteh((int)(char)ledlist[mynumber]);
also, function cwriteh() supposed do? this:
int ledlist[] = {0, 'led1[]', 'led2[]', 'led3[]', 'led4[]', 'led5[]', 'led6[]'};
says trying write strings chars into int array. really? spend time reading on arrays , try again.
cwriteh((int)(char)ledlist[mynumber]);
also, function cwriteh() supposed do? this:
int ledlist[] = {0, 'led1[]', 'led2[]', 'led3[]', 'led4[]', 'led5[]', 'led6[]'};
says trying write strings chars into int array. really? spend time reading on arrays , try again.
Arduino Forum > Using Arduino > Programming Questions > extracting a value from an array
arduino
Comments
Post a Comment