4 bits bcd input en Neopixel output

Arduino shields
Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: 4 bits bcd input en Neopixel output

Berichtdoor nicoverduin » 31 Okt 2015, 21:17

Dat komt omdat de schakelaars leest in de setup(). Die moet je lezen in de loop(). Dus moet je al die code die dat nu doet in de setup verplaatsen naar de loop.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Advertisement

Berichten: 10
Geregistreerd: 29 Dec 2014, 15:35
Woonplaats: Oosterwolde (Gld)

Re: 4 bits bcd input en Neopixel output

Berichtdoor Gert848 » 01 Nov 2015, 19:41

nicoverduin schreef:Volgens mij had ik je een voorbeeld programma gegeven waar je alleen de volgende regel hoef toe te voegen na deze regel:
cpp code
uint8_t bitje = !digitalRead(profileBitArray[i]);

deze regel erachter toevoegen
cpp code
profile += bitje;


Dus als je toch je eigen programma wilt voortzetten... dan moet je het hele stuk wat je nu doet in de setup waar je dus die bitjes leest, verplaatsen naar de loop.
Om er 6 bits van te maken heb je in jouw geval nog wel wat regels te dupliceren en aan te passen
Hallo Nico. Ik ben weer een stukje verder. Alleen als de input waarde veranderd moet de voorgaande led uit gaan. Dus eigenlijk als een input veranderd moeten alle leds op zwart gezet worden en daarna weer de actuele waarde op de monitor. Kun je nog advies geven?

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: 4 bits bcd input en Neopixel output

Berichtdoor nicoverduin » 01 Nov 2015, 20:14

Dan moet je net voordat je het juiste pixel aanzet, eerst alle pixels op zwart zetten.... ff goed kijken.... Pas bij show() worden de pixels feitelijk bijgewerkt.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 10
Geregistreerd: 29 Dec 2014, 15:35
Woonplaats: Oosterwolde (Gld)

Re: 4 bits bcd input en Neopixel output

Berichtdoor Gert848 » 01 Nov 2015, 20:31

nicoverduin schreef:Dan moet je net voordat je het juiste pixel aanzet, eerst alle pixels op zwart zetten.... ff goed kijken.... Pas bij show() worden de pixels feitelijk bijgewerkt.
Oke ik ga het proberen. Ik heb nog 1 vraag ik heb de profile -1 gedaan omdat als alle bits laag zijn led 0 brand en die wil ik als eersteled gebruiken. Die brand dus als alles "0" is .Alleen geeft hij dan ook op de monitor 1 minder aan als in werkelijkheid. Ik heb wel programma's van de neopixel gezien waar je aan kon geven hoeveel leds en welke de 1e led is. Kun je daar nog iets over vertellen? Het werkt wel zoals ik wil alleen zou het mooi zijn dat het scherm wel klopt met de juiste led.

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: 4 bits bcd input en Neopixel output

Berichtdoor nicoverduin » 01 Nov 2015, 20:34

huiswerk:...ff gaan nadenken.....
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 10
Geregistreerd: 29 Dec 2014, 15:35
Woonplaats: Oosterwolde (Gld)

Re: 4 bits bcd input en Neopixel output

Berichtdoor Gert848 » 01 Nov 2015, 21:18

nicoverduin schreef:huiswerk:...ff gaan nadenken.....
Ik begin het nog leuk te vinden maar ik ken de cpp taal nog lang niet.Ik ben meer thuis in Plc logica. Maar de wil om dit voor elkaar te krijgen is er wel. Bedankt voor je reactie.

Berichten: 10
Geregistreerd: 29 Dec 2014, 15:35
Woonplaats: Oosterwolde (Gld)

Re: 4 bits bcd input en Neopixel output

Berichtdoor Gert848 » 01 Nov 2015, 22:31

nicoverduin schreef:huiswerk:...ff gaan nadenken.....
Ik gelukt gelijk 6 bits van gemaakt. Bedankt voor het huiswerk.
[code]// TEST For "Profile switch" currently set to read BCD switch
// once during setup; move code as noted below for repeated reads

// BCD Switch inputs attached to pins D2-8, common to Ground
// (use internal pullups)

#include <Adafruit_NeoPixel.h>
#include <avr/power.h>


// The Neopixels will be attached to pin 6
#define PIN 6

// How many Neopixels are attached to the Arduino?
#define NUMPIXELS 64

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS,PIN, NEO_GRB + NEO_KHZ800);


// Define data bit pins
int profile_BIT1 = 2;
int profile_BIT2 = 3;
int profile_BIT4 = 4;
int profile_BIT8 = 5;
int profile_BIT16 = 7;
int profile_BIT32 = 8;

// Define profile variable, set to 0

int profile = 0;

void setup() {
// initialize serial communication at 9600 bits per second (only needed
// for debugging:

Serial.begin(9600);
}


void loop() {

pixels.begin(); // This initializes the NeoPixel library.


// make the profile switch's pins inputs, with internal pullups on:
pinMode(profile_BIT1, INPUT_PULLUP);
pinMode(profile_BIT2, INPUT_PULLUP);
pinMode(profile_BIT4, INPUT_PULLUP);
pinMode(profile_BIT8, INPUT_PULLUP);
pinMode(profile_BIT16, INPUT_PULLUP);
pinMode(profile_BIT32, INPUT_PULLUP);

// to make read on each pass move all below this to "loop",
// uncomment profile reset


// read the input pins: NOTE - CLOSED switch (binary 1) returns "0"
int val_profile_BIT1 = digitalRead(profile_BIT1);
int val_profile_BIT2 = digitalRead(profile_BIT2);
int val_profile_BIT4 = digitalRead(profile_BIT4);
int val_profile_BIT8 = digitalRead(profile_BIT8);
int val_profile_BIT16 = digitalRead(profile_BIT16);
int val_profile_BIT32 = digitalRead(profile_BIT32);



int profile = 0;
// needed in loop to reset to 0 for each pass

//turn bit values into single profile value by adding decimal value
//of each bit to profile variable

if ( val_profile_BIT1 == 0) { profile = profile + 1; }
if ( val_profile_BIT2 == 0) { profile = profile + 2; }
if ( val_profile_BIT4 == 0) { profile = profile + 4; }
if ( val_profile_BIT8 == 0) { profile = profile + 8; }
if ( val_profile_BIT16 == 0) { profile = profile + 16; }
if ( val_profile_BIT32 == 0) { profile = profile + 32; }

//DEBUG - prints out the state of the switch bits and profile value

{Serial.print("[profile_BIT1: ");
Serial.print(val_profile_BIT1);
Serial.print("] ");
Serial.print("[profile_BIT2: ");
Serial.print(val_profile_BIT2);
Serial.print("] ");
Serial.print("[profile_BIT4: ");
Serial.print(val_profile_BIT4);
Serial.print("] ");
Serial.print("[profile_BIT8: ");
Serial.print(val_profile_BIT8);
Serial.print("] ");
Serial.print("[profile_BIT16: ");
Serial.print(val_profile_BIT16);
Serial.print("] ");
Serial.print("[profile_BIT32: ");
Serial.print(val_profile_BIT32);
Serial.print("] ");
Serial.print("[profile: ");
Serial.print(profile);
Serial.println("] ");}


// delay in between reads for stability, uncomment if in loop
//delay(1000);
pixels.setPixelColor(profile-1, 0,0,50);
pixels.show();
//delay(1000);
pixels.setPixelColor(profile-1, 0,0,0);
//delay(1000);

}

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: 4 bits bcd input en Neopixel output

Berichtdoor nicoverduin » 02 Nov 2015, 08:59

Let wel dat je nu geen BCD (binary Coded Decimal) inputs hebt maar gewoon Binary. In het eerste geval geeft een duimwiel schakelaar een binair patroon af van 0-9. Dus bij 63 heb je 2 duimwielen nodig die 6-3 aangeven. Bianair wordt dat dan 0110 0011. Deze waarde echter zou hoger zijn dan jij verwacht. Namelijk 99.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Vorige

Terug naar Shields

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 3 gasten