Arduino power input.
5 berichten
• Pagina 1 van 1
- Jeroentjevrij
- Berichten: 82
- Geregistreerd: 27 Feb 2019, 11:19
Arduino power input.
Ik heb een led kubus gebouwd.
En alle componenten met een externe voeding van 5v voorzien.
Ook mijn arduino.
Maar nu wil ik hem van code gaan voorzien.
Maar nu is de vraag moet ik als ik de usb inplug eerst de 5v voeding verwijderen.
Omdat de usb ook 5v levert.
En alle componenten met een externe voeding van 5v voorzien.
Ook mijn arduino.
Maar nu wil ik hem van code gaan voorzien.
Maar nu is de vraag moet ik als ik de usb inplug eerst de 5v voeding verwijderen.
Omdat de usb ook 5v levert.
Advertisement
Re: Arduino power input.
Ja eigenlijk wel. Als de voeding op Vin staat dan hoeft het niet maar daar is het van 7 tot 12 Volt.
Denk er wel aan om dan de leds even los te koppelen, want anders blaas je de usb op.
Je kunt natuurlijk ook de USB voeding voorzien van een diode.
Denk er wel aan om dan de leds even los te koppelen, want anders blaas je de usb op.
Je kunt natuurlijk ook de USB voeding voorzien van een diode.
paul deelen
shooter@home.nl
shooter@home.nl
- Jeroentjevrij
- Berichten: 82
- Geregistreerd: 27 Feb 2019, 11:19
Re: Arduino power input.
Als ik mijn compile doe.
Zegt het programma (error return code is not 0)
Weet iemand hoe dit op te lossen
Zegt het programma (error return code is not 0)
- Code: Alles selecteren
# include < SPI.h >
# define XAXIS 0
# define YAXIS 1
# define ZAXIS 2
# define POS_X 0
# define NEG_X 1
# define POS_Z 2
# define NEG_Z 3
# define POS_Y 4
# define NEG_Y 5
# define BUTTON_PIN 8
# define RED_LED 5
# define GREEN_LED 7
# define TOTAL_EFFECTS 8
# define RAIN 0
# define PLANE_BOING 1
# define SEND_VOXELS 2
# define WOOP_WOOP 3
# define CUBE_JUMP 4
# define GLOW 5
# define TEXT 6
# define LIT 7
# define RAIN_TIME 260
# define PLANE_BOING_TIME 220
# define SEND_VOXELS_TIME 140
# define WOOP_WOOP_TIME 350
# define CUBE_JUMP_TIME 200
# define GLOW_TIME 8
# define TEXT_TIME 300
# define CLOCK_TIME 500
uint8_t tekens [ 10 ] [ 8 ] = {
{ 0x3C , 0x42 , 0x42 , 0x42 , 0x42 , 0x42 , 0x42 , 0x3C }, // 0
{ 0x10 , 0x18 , 0x14 , 0x10 , 0x10 , 0x10 , 0x10 , 0x3C }, // 1
{ 0x3C , 0x42 , 0x40 , 0x40 , 0x3C , 0x02 , 0x02 , 0x7E }, // 2
{ 0x3C , 0x40 , 0x40 , 0x3C , 0x40 , 0x40 , 0x42 , 0x3C }, // 3
{ 0x22 , 0x22 , 0x22 , 0x22 , 0x7E , 0x20 , 0x20 , 0x20 }, // 4
{ 0x7E , 0x02 , 0x02 , 0x3E , 0x40 , 0x40 , 0x42 , 0x3C }, // 5
{ 0x3C , 0x02 , 0x02 , 0x3E , 0x42 , 0x42 , 0x42 , 0x3C }, // 6
{ 0x3C , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 }, // 7
{ 0x3C , 0x42 , 0x42 , 0x3C , 0x42 , 0x42 , 0x42 , 0x3C }, // 8
{ 0x3C , 0x42 , 0x42 , 0x42 , 0x3C , 0x40 , 0x40 , 0x3C }, // 9
};
uint8_t cube [ 8 ] [ 8 ];
uint8_t currentEffect ;
uint16_t timer;
uint64_t randomTimer;
bool laden;
void setup () {
laden = waar ;
randomTimer = 0 ;
currentEffect = RAIN;
SPI. begin ();
SPI. beginTransaction ( SPISettings ( 8000000 , MSBFIRST, SPI_MODE0));
pinMode (BUTTON_PIN, INPUT_PULLUP);
pinMode (RED_LED, OUTPUT);
pinMode (GREEN_LED, OUTPUT);
randomSeed ( analoogLees ( 0 ));
digitalWrite (GREEN_LED, HIGH);
}
void loop () {
randomTimer ++;
if ( digitalRead (BUTTON_PIN) == LOW) {
clearCube ();
laden = waar ;
timer = 0 ;
currentEffect ++;
if (currentEffect == TOTAL_EFFECTS) {
currentEffect = 0 ;
}
randomSeed (randomTimer);
randomTimer = 0 ;
digitalWrite (RED_LED, HIGH);
digitalWrite (GREEN_LED, LOW);
vertraging ( 500 );
digitalWrite (RED_LED, LOW);
digitalWrite (GREEN_LED, HIGH);
}
switch (currentEffect) {
geval REGEN: regen (); pauze ;
case PLANE_BOING: planeBoing (); pauze ;
case SEND_VOXELS: sendVoxels (); pauze ;
case WOOP_WOOP: woopWoop (); pauze ;
case CUBE_JUMP: cubeJump (); pauze ;
geval GLOW: glow (); pauze ;
case TEXT: text ( " 0123456789 " , 10 ); pauze ;
case LIT: lit (); pauze ;
standaard : regen ();
}
renderCube ();
}
void renderCube () {
for ( uint8_t i = 0 ; i < 8 ; i ++) {
digitalWrite (SS, LOW);
SPI. overdracht ( 0x01 << i);
for ( uint8_t j = 0 ; j < 8 ; j ++) {
SPI. overdracht (kubus [i] [j]);
}
digitalWrite (SS, HIGH);
}
}
ongeldige regen () {
if (laden) {
clearCube ();
laden = onwaar ;
}
timer ++;
if (timer> RAIN_TIME) {
timer = 0 ;
shift (NEG_Y);
uint8_t numDrops = willekeurig ( 0 , 5 );
for ( uint8_t i = 0 ; i <numDrops; i ++) {
setVoxel ( willekeurig ( 0 , 8 ), 7 , willekeurig ( 0 , 8 ));
}
}
}
uint8_t planePosition = 0 ;
uint8_t planeDirection = 0 ;
bool lus = false ;
void planeBoing () {
if (laden) {
clearCube ();
uint8_t as = willekeurig ( 0 , 3 );
planePosition = willekeurig ( 0 , 2 ) * 7 ;
setPlane (axis, planePosition);
if (axis == XAXIS) {
if (planePosition == 0 ) {
planeDirection = POS_X;
} else {
planeDirection = NEG_X;
}
} else if (axis == YAXIS) {
if (planePosition == 0 ) {
planeDirection = POS_Y;
} else {
planeDirection = NEG_Y;
}
} else if (axis == ZAXIS) {
if (planePosition == 0 ) {
planeDirection = POS_Z;
} else {
planeDirection = NEG_Z;
}
}
timer = 0 ;
looped = false ;
laden = onwaar ;
}
timer ++;
if (timer> PLANE_BOING_TIME) {
timer = 0 ;
shift (planeDirection);
if (planeDirection% 2 == 0 ) {
planePosition ++;
if (planePosition == 7 ) {
if (looped) {
laden = waar ;
} else {
planeDirection ++;
looped = true ;
}
}
} else {
planePosition--;
if (planePosition == 0 ) {
if (looped) {
laden = waar ;
} else {
planeDirection--;
looped = true ;
}
}
}
}
}
uint8_t selX = 0 ;
uint8_t selY = 0 ;
uint8_t selZ = 0 ;
uint8_t sendDirection = 0 ;
bool sending = false ;
void sendVoxels () {
if (laden) {
clearCube ();
for ( uint8_t x = 0 ; x < 8 ; x ++) {
for ( uint8_t z = 0 ; z < 8 ; z ++) {
setVoxel (x, willekeurig ( 0 , 2 ) * 7 , z);
}
}
laden = onwaar ;
}
timer ++;
if (timer> SEND_VOXELS_TIME) {
timer = 0 ;
if (! sending) {
selX = willekeurig ( 0 , 8 );
selZ = willekeurig ( 0 , 8 );
if ( getVoxel (selX, 0 , selZ)) {
selY = 0 ;
sendDirection = POS_Y;
} else if ( getVoxel (selX, 7 , selZ)) {
selY = 7 ;
sendDirection = NEG_Y;
}
verzenden = waar ;
} else {
if (sendDirection == POS_Y) {
Sely ++;
setVoxel (selX, selY, selZ);
clearVoxel (selX, selY - 1 , selZ);
if (selY == 7 ) {
verzenden = false ;
}
} else {
selY--;
setVoxel (selX, selY, selZ);
clearVoxel (selX, selY + 1 , selZ);
if (selY == 0 ) {
verzenden = false ;
}
}
}
}
}
uint8_t cubeSize = 0 ;
bool cubeExpanding = true ;
void woopWoop () {
if (laden) {
clearCube ();
cubeSize = 2 ;
cubeExpanding = true ;
laden = onwaar ;
}
timer ++;
if (timer> WOOP_WOOP_TIME) {
timer = 0 ;
if (cubeExpanding) {
cubeSize + = 2 ;
if (cubeSize == 8 ) {
cubeExpanding = false ;
}
} else {
cubeSize - = 2 ;
if (cubeSize == 2 ) {
cubeExpanding = true ;
}
}
clearCube ();
drawCube ( 4 - cubeSize / 2 , 4 - cubeSize / 2 , 4 - cubeSize / 2 , cubeSize);
}
}
uint8_t xPos;
uint8_t yPos;
uint8_t zPos;
void cubeJump () {
if (laden) {
clearCube ();
xPos = willekeurig ( 0 , 2 ) * 7 ;
yPos = willekeurig ( 0 , 2 ) * 7 ;
zPos = willekeurig ( 0 , 2 ) * 7 ;
cubeSize = 8 ;
cubeExpanding = false ;
laden = onwaar ;
}
timer ++;
if (timer> CUBE_JUMP_TIME) {
timer = 0 ;
clearCube ();
if (xPos == 0 && yPos == 0 && zPos == 0 ) {
drawCube (xPos, yPos, zPos, cubeSize);
} else if (xPos == 7 && yPos == 7 && zPos == 7 ) {
drawCube (xPos + 1 - cubeSize, yPos + 1 - cubeSize, zPos + 1 - cubeSize, cubeSize);
} else if (xPos == 7 && yPos == 0 && zPos == 0 ) {
drawCube (xPos + 1 - cubeSize, yPos, zPos, cubeSize);
} else if (xPos == 0 && yPos == 7 && zPos == 0) {
drawCube(xPos, yPos + 1 - cubeSize, zPos, cubeSize);
} else if (xPos == 0 && yPos == 0 && zPos == 7) {
drawCube(xPos, yPos, zPos + 1 - cubeSize, cubeSize);
} else if (xPos == 7 && yPos == 7 && zPos == 0) {
drawCube(xPos + 1 - cubeSize, yPos + 1 - cubeSize, zPos, cubeSize);
} else if (xPos == 0 && yPos == 7 && zPos == 7) {
drawCube(xPos, yPos + 1 - cubeSize, zPos + 1 - cubeSize, cubeSize);
} else if (xPos == 7 && yPos == 0 && zPos == 7) {
drawCube(xPos + 1 - cubeSize, yPos, zPos + 1 - cubeSize, cubeSize);
}
if (cubeExpanding) {
cubeSize++;
if (cubeSize == 8) {
cubeExpanding = false;
xPos = random(0, 2) * 7;
yPos = random(0, 2) * 7;
zPos = random(0, 2) * 7;
}
} else {
cubeSize--;
if (cubeSize == 1) {
cubeExpanding = true;
}
}
}
}
bool glowing;
uint16_t glowCount = 0;
void glow() {
if (loading) {
clearCube();
glowCount = 0;
glowing = true;
loading = false;
}
timer++;
if (timer > GLOW_TIME) {
timer = 0;
if (glowing) {
if (glowCount < 448) {
do {
selX = random(0, 8);
selY = random(0, 8);
selZ = random(0, 8);
} while (getVoxel(selX, selY, selZ));
setVoxel (selX, selY, selZ);
glowCount ++;
} else if (glowCount < 512 ) {
lightCube ();
glowCount ++;
} else {
gloeien = onwaar ;
glowCount = 0 ;
}
} else {
if (glowCount < 448 ) {
doen {
selX = willekeurig ( 0 , 8 );
selY = willekeurig ( 0 , 8 );
selZ = willekeurig ( 0 , 8 );
} while (! getVoxel (selX, selY, selZ));
clearVoxel (selX, selY, selZ);
glowCount ++;
} else {
clearCube ();
gloeien = waar ;
glowCount = 0 ;
}
}
}
}
uint8_t charCounter = 0 ;
uint8_t charPosition = 0 ;
void text ( char string [], uint8_t len) {
if (laden) {
clearCube ();
charPosition = - 1 ;
charCounter = 0 ;
laden = onwaar ;
}
timer ++;
if (timer> TEXT_TIME) {
timer = 0 ;
shift (NEG_Z);
charPosition ++;
if (charPosition == 7 ) {
charCounter ++;
if (charCounter> len - 1 ) {
charCounter = 0 ;
}
charPosition = 0 ;
}
if (charPosition == 0 ) {
for ( uint8_t i = 0 ; i < 8 ; i ++) {
kubus [i] [ 0 ] = tekens [tekenreeks [charCounter] - ' 0 ' ] [i];
}
}
}
}
ongeldig verlicht () {
if (laden) {
clearCube ();
for ( uint8_t i = 0 ; i < 8 ; i ++) {
for ( uint8_t j = 0 ; j < 8 ; j ++) {
kubus [i] [j] = 0xFF ;
}
}
laden = onwaar ;
}
}
void setVoxel ( uint8_t x, uint8_t y, uint8_t z) {
kubus [ 7 - y] [ 7 - z] | = ( 0x01 << x);
}
void clearVoxel ( uint8_t x, uint8_t y, uint8_t z) {
kubus [ 7 - y] [ 7 - z] ^ = ( 0x01 << x);
}
bool getVoxel ( uint8_t x, uint8_t y, uint8_t z) {
return (kubus [ 7 - y] [ 7 - z] & ( 0x01 << x)) == ( 0x01 << x);
}
void setPlane ( uint8_t axis, uint8_t i) {
for ( uint8_t j = 0 ; j < 8 ; j ++) {
for ( uint8_t k = 0 ; k < 8 ; k ++) {
if (axis == XAXIS) {
setVoxel (i, j, k);
} else if (axis == YAXIS) {
setVoxel (j, i, k);
} else if (axis == ZAXIS) {
setVoxel (j, k, i);
}
}
}
}
void shift ( uint8_t dir) {
if (dir == POS_X) {
for ( uint8_t y = 0 ; y < 8 ; y ++) {
for ( uint8_t z = 0 ; z < 8 ; z ++) {
kubus [y] [z] = kubus [y] [z] << 1 ;
}
}
} else if (dir == NEG_X) {
for ( uint8_t y = 0 ; y < 8 ; y ++) {
for ( uint8_t z = 0 ; z < 8 ; z ++) {
kubus [y] [z] = kubus [y] [z] >> 1 ;
}
}
} else if (dir == POS_Y) {
for ( uint8_t y = 1 ; y < 8 ; y ++) {
for ( uint8_t z = 0 ; z < 8 ; z ++) {
kubus [y - 1 ] [z] = kubus [y] [z];
}
}
for ( uint8_t i = 0 ; i < 8 ; i ++) {
kubus [ 7 ] [i] = 0 ;
}
} else if (dir == NEG_Y) {
for ( uint8_t y = 7 ; y> 0 ; y--) {
for ( uint8_t z = 0 ; z < 8 ; z ++) {
kubus [y] [z] = kubus [y - 1 ] [z];
}
}
for ( uint8_t i = 0 ; i < 8 ; i ++) {
kubus [ 0 ] [i] = 0 ;
}
} else if (dir == POS_Z) {
for ( uint8_t y = 0 ; y < 8 ; y ++) {
for ( uint8_t z = 1 ; z < 8 ; z ++) {
kubus [y] [z - 1 ] = kubus [y] [z];
}
}
for ( uint8_t i = 0 ; i < 8 ; i ++) {
kubus [i] [ 7 ] = 0 ;
}
} else if (dir == NEG_Z) {
for ( uint8_t y = 0 ; y < 8 ; y ++) {
for ( uint8_t z = 7 ; z> 0 ; z--) {
kubus [y] [z] = kubus [y] [z - 1 ];
}
}
for ( uint8_t i = 0 ; i < 8 ; i ++) {
kubus [i] [ 0 ] = 0 ;
}
}
}
void drawCube ( uint8_t x, uint8_t y, uint8_t z, uint8_t s) {
for ( uint8_t i = 0 ; i <s; i ++) {
setVoxel (x, y + i, z);
setVoxel (x + i, y, z);
setVoxel (x, y, z + i);
setVoxel (x + s - 1 , y + i, z + s - 1 );
setVoxel (x + i, y + s - 1 , z + s - 1 );
setVoxel (x + s - 1 , y + s - 1 , z + i);
setVoxel (x + s - 1 , y + i, z);
setVoxel (x, y + i, z + s - 1 );
setVoxel (x + i, y + s - 1 , z);
setVoxel (x + i, y, z + s - 1 );
setVoxel (x + s - 1 , y, z + i);
setVoxel (x, y + s - 1 , z + i);
}
}
void lightCube () {
for ( uint8_t i = 0 ; i < 8 ; i ++) {
for ( uint8_t j = 0 ; j < 8 ; j ++) {
kubus [i] [j] = 0xFF ;
}
}
}
void clearCube () { leegmaken }
for ( uint8_t i = 0 ; i < 8 ; i ++) {
for ( uint8_t j = 0 ; j < 8 ; j ++) {
kubus [i] [j] = 0 ;
}
}
}
Weet iemand hoe dit op te lossen
Re: Arduino power input.
Ik krijg normale foutmeldingen.
Bijvoorbeeld #include < SPI.h > hoort nodig zonder spaties te zijn.
En "ongeldige regen ()" en "ongeldig verlicht ()" zijn geen functie declaraties.
Ook "gloeien = waar ;" kan niet, want "waar" bestaat niet.
De "analoogLees ( 0 )" is niet correct.
De aanroep "vertraging ( 500 );" kan niet, want "vertraging" is geen functie.
Ook "geval REGEN:" kan niet in de c++ taal.
En zo nog een stuk 40 andere fouten.
Heb je eerder een programma geschreven? Misschien kun je beter met een eenvoudige sketch beginnen, bijvoorbeeld een ledje laten knipperen.
Jouw code lijkt van internet te zijn gekopieerd en door Google Translate te zijn gehaald.
Ik weet niet of iemand zin heeft om alles voor je te corrigeren. Waar komt het vandaan ?
Bijvoorbeeld #include < SPI.h > hoort nodig zonder spaties te zijn.
En "ongeldige regen ()" en "ongeldig verlicht ()" zijn geen functie declaraties.
Ook "gloeien = waar ;" kan niet, want "waar" bestaat niet.
De "analoogLees ( 0 )" is niet correct.
De aanroep "vertraging ( 500 );" kan niet, want "vertraging" is geen functie.
Ook "geval REGEN:" kan niet in de c++ taal.
En zo nog een stuk 40 andere fouten.
Heb je eerder een programma geschreven? Misschien kun je beter met een eenvoudige sketch beginnen, bijvoorbeeld een ledje laten knipperen.
Jouw code lijkt van internet te zijn gekopieerd en door Google Translate te zijn gehaald.
Ik weet niet of iemand zin heeft om alles voor je te corrigeren. Waar komt het vandaan ?
- Jeroentjevrij
- Berichten: 82
- Geregistreerd: 27 Feb 2019, 11:19
Re: Arduino power input.
Ja idd me telefoon heeft het vertaal haha.
De code komt van github.
Kan zelf niet programmeren dus zocht een kant en klaar code op internet.
De code komt van github.
Kan zelf niet programmeren dus zocht een kant en klaar code op internet.
5 berichten
• Pagina 1 van 1
Wie is er online?
Gebruikers in dit forum: Geen geregistreerde gebruikers en 0 gasten