Hello, world!

+3 Adam Karrer · September 6, 2014
Hey guys, my name is Adam, I'm turning 26 next month, and I live in southern New Jersey. I work at a vape shop currently, and I'm kinda-sorta working on my associates in Database Design and Development. I know a bit of Java and I'm currently learning Python and SQL. I play around with Arduino, Raspberry Pi, and some other random unknown microcontroller that's sitting in my drawer sometimes, and I should be adding a 3D printer to my collection of toys soon.

Bucky's videos really accelerated my learning during my college courses, and they are the only video tutorials that I don't fall asleep during, so I became a fan of his about a year or so ago. I'm hoping being on here will further help me learn some epic tuna coding skills, so I can land a job one day slowly giving myself carpal tunnel and drinking coffee by the gallons.

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
0 Samiha Shaheed · January 23, 2015
oops!

/*
    ledcube.pde - Example sketch for controlling an LED cube.
    Created by Gamaiel Zavala (gzip), 2009-2014
    MIT License. See accompanying LICENSE file for terms.
*/

#include <LedCube.h>
#include <LedCube.cpp>
#define SIZE 3
#define COLS (SIZE*SIZE)

byte levelPins[SIZE] = {11,12,13};
byte colPins[COLS] = {2,3,4,5,6,7,8,9,10};

LedCube cube(SIZE, levelPins, colPins);

//#define DEBUG
#ifdef DEBUG
#include <memdebug.h>
void showmem(const char label[] = "")
{
  char buffer[100];
 
  sprintf(buffer,"%s: %04u %04u : used/free",
      label,
      getMemoryUsed(),
      getFreeMemory()
    );
 
  Serial.println(buffer);
}
#endif

void setup ()
{
#ifdef DEBUG
    Serial.begin(9600);
#endif
}

void loop ()
{
    delay(10);
    
#ifdef DEBUG
    showmem("start");
#endif
    // paste UI output here (https://rawgithub.com/gzip/arduino-ledcube/master/ui/index.html)
    cubeFrame* f[] = {
        cube.createFrame((const byte[]) {0,6, 1,6, 2,6}, 6, 80),
        cube.createFrame((const byte[]) {0,7, 1,7, 2,7}, 6, 70),
        cube.createFrame((const byte[]) {0,8, 1,8, 2,8}, 6, 60),
        cube.createFrame((const byte[]) {0,5, 1,5, 2,5}, 6, 50),
        cube.createFrame((const byte[]) {0,2, 1,2, 2,2}, 6, 40),
        cube.createFrame((const byte[]) {0,1, 1,1, 2,1}, 6, 30),
        cube.createFrame((const byte[]) {0,0, 1,0, 2,0}, 6, 20),
        cube.createFrame((const byte[]) {0,3, 1,3, 2,3}, 6, 10)
    };
#ifdef DEBUG
    showmem("before free");
#endif
    cube.lightFrames(f, 8);
    
    // light each light one at a time
    for(byte level=0; level<cube.getLevels(); level++)
    {
        for(byte col=0; col<cube.getCols(); col++)
        {
            cube.lightPulse(level, col, 100);
        }
    }
    
    // light one level at a time, increasing speed each time
    for(byte d=25; d>2; d-=2)
    {
        for(byte l=1; l <= cube.getLevels(); l++)
        {
            cube.lightLevel(l, d);
        }
    }
    
    // light each row on each level
    for(byte level=1; level<=cube.getLevels(); level++)
    {
        for(byte row=1; row<=cube.getLevels()*2; row++)
        {
            cube.lightRow(row, level);
        }
    }
    
    // light each plane
    for(byte i=3; i; i--)
    {
        for(byte row=1; row<=cube.getLevels()*2; row++)
        {
            cube.lightPlane(row, 10*i);
        }
    }
    
    // single random light at a time
    cube.randomLight(random(25,100),100);
    
    // random column drop
    for(byte x=0; x<=15; x++)
    {
        cube.lightDrop(random(0,cube.getCols()), random(50,150));
    }
    
    // circle around cube at a random level
    for(byte x=0; x<=5; x++)
    {
        cube.lightPerimeter(random(0,cube.getLevels()), random(1,5), random(25,100));
    }
    
    // light each face
    byte planes[] = {cube.getLevels()+1,cube.getLevels(),cube.getLevels()*2,1};
    for(byte i=5; i; i--)
    {
        for(byte p=0; p<sizeof(planes); p++)
        {
            cube.lightPlane(planes[p], 5*i);
        }
    }
    
    // random columns
    cube.randomColumn(25);
    
    // turn off a single column randomly
    cube.enableBuffer();
    for(byte c=0; c<30; c++)
    {
        cube.fillBuffer();
        cube.invertBuffer();
        cube.randomColumn();
        cube.drawBuffer(7);
    }
    cube.enableBuffer(false);
    
    // cols in and out
    for(byte c=1, d=0; c<=10; c++)
    {
        if(c%2 == 0)
        {
            for(d=0; d<20; d++)
            {
                cube.lightColumn(2,1);
                cube.lightColumn(4,1);
                cube.lightColumn(6,1);
                cube.lightColumn(8,1);
            }
        }
        else if(c%4 == 1)
        {
            for(d=0; d<30; d++)
            {
                cube.lightColumn(1,1);
                cube.lightColumn(3,1);
                cube.lightColumn(7,1);
                cube.lightColumn(9,1);
            }
        }
        else
        {
            for(d=0; d<70; d++)
            {
                cube.lightColumn(5,1);
            }
        }
    }
    
    // diamond and box
    byte diamond[] = {0,4,  1,1, 1,3, 1,4, 1,5, 1,7,   2,4};
    byte box[] = {
        2,0, 2,1, 2,2, 2,3, 2,5, 2,6, 2,7, 2,8,
        1,0, 1,2, 1,6, 1,8,
        0,0, 0,1, 0,2, 0,3, 0,5, 0,6, 0,7, 0,8
    };
    cube.lightSequence(box, sizeof(box), 200);
    cube.lightSequence(diamond, sizeof(diamond), 400);
    
    // helicopter effect
    byte topSeq[8] = {0,3,6,7,8,5,2,1};
    byte botSeq[8] = {8,5,2,1,0,3,6,7};
    for(byte loops = 0, delay = 50; loops<=8; loops++)
    {
        for(byte s=0; s<8; s++)
        {
            byte seq[] = {2,topSeq, 1,4, 0,botSeq};
            cube.lightSequence(seq, sizeof(seq), delay);
        } 
        if(loops < 5) delay-=10;  else delay += 10;
    }
    
    // turn off one light at a time
    cube.lightsOut();
}
0 Mathias Frits Rørvik · January 23, 2015
That is not your source code. That is someone else code. Where is void setup(), and void loop() ?
0 Samiha Shaheed · January 23, 2015

/*
    LedCube.cpp - Library for controlling an LED cube
    Created by Gamaiel Zavala (gzip), 2009-2012
    MIT License. See accompanying LICENSE file for terms.
*/

#include <new.h>
#include "newfix.h"
#include "LedCube.h"

LedCube::LedCube(byte size, byte lp[], byte cp[]) :
    levels(size), cols(size*size), num(size*size*size),
    bufferEnabled(false), bufferInverted(false)
{
    randomSeed(analogRead(0));
    
    // allocate memory for dynamic members
    buffer = new byte*[levels];
    levelPins = new byte[levels];
    colPins = new byte[cols];
    
    // configure level pins and finish allocation for buffer
    for (byte i = 0; i < levels; i++)
    {
        levelPins = lp;
        pinMode(levelPins, OUTPUT);
        
        buffer = new byte[cols];
    }
    
    // configure column pins
    for (byte i = 0; i < cols; i++)
    {
        colPins = cp;
        pinMode(colPins, OUTPUT);
    }
    
    clearBuffer();
    
    //Serial.begin(9600);
}

// destructor frees dynamically allocated memory
LedCube::~LedCube()
{
    for (byte i = 0; i < levels; i++)
    {
        delete buffer;
    }
    delete buffer;
    delete levelPins;
    delete colPins;
}

// low level methods, zero based

void LedCube::light(byte lv, byte col, byte val)
{
    if(lv < levels && col < cols)
    {
        if(bufferEnabled)
        {
            buffer[lv] = val;
        }
        else
        {
            digitalWrite(colPins, val);
            digitalWrite(levelPins[lv], val);
        }
    }
}

void LedCube::lightOff(byte level, byte col)
{
    light(level,col,(bufferInverted ? HIGH : LOW));
}

void LedCube::lightOn(byte lv, byte col)
{
    light(lv,col,(bufferInverted ? LOW : HIGH));
}

void LedCube::lightPulse(byte lv, byte col, unsigned int wait)
{
    lightOn(lv, col);
    if(!bufferEnabled)
    {
        delay(wait);
        lightOff(lv, col);
    }
}

// basic effects

void LedCube::randomLight(byte numLights, unsigned int wait)
{
    for (byte l=0; l<numLights; l++)
    {
        lightPulse(random(0,levels), random(0,cols), wait);
    } 
}

void LedCube::lightDrop(byte col, unsigned int wait)
{
     for(byte r=levels; r; r--)
     {
         lightPulse(r-1, col-1, wait);
     }
}

// sequence effects

// time is overall, gap is in between individual lights
void LedCube::lightSequence(byte seq[], byte length, unsigned int time, byte gap)
{
    // should be pairs of coords
    if(length%2){ return; }
    
    if(bufferEnabled){ time = 1; }
    
    //Serial.print('{');
    for (unsigned int d=0; d<time; d++)
    {
        for (byte s=0; s<length; s+=2)
        {
            if(bufferEnabled){
                 lightOn(seq, seq[s+1]);
            } else {
                 lightPulse(seq,seq[s+1], gap);
            }
            //Serial.print(seq,DEC); if(s < length-1) Serial.print(', ');
        } 
    }
    //Serial.println('}');
}

cubeFrame* LedCube::createFrame(const byte sequence[], unsigned int size, unsigned int delay)
{
    // allocate memory which will be reclaimed in lightFrames
    struct cubeFrame *f = (cubeFrame*) malloc(sizeof(struct cubeFrame));
    f->sequence = (byte*) malloc(sizeof(byte) * size);
    memcpy((void*) f->sequence , (void*) sequence, sizeof(byte) * size);
    f->size = size;
    f->delay = delay;
    return f;
}

void LedCube::destroyFrame(cubeFrame* frame)
{
    free(frame->sequence);
    free(frame);
}

void LedCube::lightFrames(cubeFrame* frames[], unsigned int length)
{
    for(byte f=0; f<length; f++)
    {
        lightSequence(frames[f]->sequence, frames[f]->size, frames[f]->delay);
        // reclaim memory allocated in createFrame to prevent a leak
        destroyFrame(frames[f]);
    }
}

void LedCube::lightLevel(byte lv, unsigned int delay)
{
    if(lv && lv<=levels)
    {
        byte seq[cols*2];
        for(byte c=0, i=0; c<cols; c++, i+=2)
        {
             seq = lv-1;
             seq[i+1] = c;
        }
        lightSequence(seq,sizeof(seq),delay);
    }
}

void LedCube::lightRow(byte r, byte level, unsigned int wait)
{
    if(r && level && r<=cols*2 && level<=levels)
    {
        byte start = r<=levels ? r-1 : (r - levels - 1) * levels;
        byte inc = r<=levels ? levels : 1;
        
        byte seq[] = {level-1,start, level-1,start+inc, level-1,start+inc*2};
        
        lightSequence(seq, sizeof(seq), wait);
    }
}

void LedCube::lightPlane(byte r, unsigned int wait)
{
    if(r && r<=cols*2)
    {
        byte start = r<=levels ? r-1 : (r - levels - 1) * levels;
        byte inc = r<=levels ? levels : 1;
        byte seq[cols*2];
        byte index = 0;
        
        for(byte level=0; level<levels; level++)
        {
            for(byte i=0; i<3; i++)
            {
                seq[index] = level;
                seq[index+1] = start + inc*i;
                index += 2;
            }
        }
        
        lightSequence(seq, sizeof(seq), wait);
    }
}

void LedCube::lightColumn(byte col, unsigned int wait)
{
    if(col && col<=cols)
    {
        byte seq[] = {0,col-1,1,col-1,2,col-1};
        lightSequence(seq,sizeof(seq),wait);
    }
}

void LedCube::lightPerimeter(byte level, byte rotations, unsigned int wait)
{
    byte seq[] = {level,0,level,1,level,2,level,5,level,8,level,7,level,6,level,3};
    lightSequence(seq, sizeof(seq), rotations, wait);
}

void LedCube::randomColumn(byte numColumns, unsigned int wait)
{
    for (byte c=0; c < numColumns; c++) {
        lightColumn(random(1,cols+1), wait);
    } 
}

// buffer methods

void LedCube::enableBuffer(boolean enable)
{
    bufferEnabled = enable;
    if(!bufferEnabled) invertBuffer(false);
}

void LedCube::invertBuffer(boolean invert)
{
    bufferInverted = invert;
}
    
void LedCube::clearBuffer()
{
     setBuffer(0);
}

void LedCube::fillBuffer()
{
     setBuffer(1);
}

void LedCube::setBuffer(byte val)
{
    for(byte lv=0; lv < levels; lv++)
        for(byte col=0; col < cols; col++)
            buffer[lv] = val;
}

byte LedCube::getBufferAt(byte lv, byte col)
{
    return buffer[lv];
}

void LedCube::drawBuffer(unsigned int wait)
{
    byte seq[num*2];
    byte n = 0;
    
    for(byte lv=0; lv<levels; lv++)
    {
        for(byte col=0; col<cols; col++)
        {
            if(buffer[lv])
            {
                //Serial.print(buffer,DEC); Serial.print(': ');
                //Serial.print(r,DEC); Serial.print(','); Serial.print(c,DEC); Serial.print(' ');
                seq[n] = lv;
                seq[n+1] = col;
                n += 2;
            }
        } 
    }
    // Serial.print('('); Serial.println(num,DEC); Serial.print(')');
    
    enableBuffer(false);
    lightSequence(seq, sizeof(seq), wait);
    enableBuffer();
}

void LedCube::lightsOut(unsigned int wait)
{
    enableBuffer();
    fillBuffer();
    drawBuffer(25);
    for(byte w=0, l, c, max = num; w<max; )
    {
        // lower bound is inclusive, upper is exclusive
        l = random(0, levels);
        c = random(0, cols);
        
        if(getBufferAt(l,c) == HIGH)
        {
            lightOff(l,c);
            drawBuffer(wait);
            w++;
        }
    }
    enableBuffer(false);
}
0 Mathias Frits Rørvik · January 21, 2015
Could you post your source code?
0 Samiha Shaheed · January 21, 2015
@Mathias Frits  Yes I am using the Arduino IDE
0 Mathias Frits Rørvik · January 21, 2015
Samiha Shahee, you could have posted this in the C or C++ section. Anyway, are you using the official Arduino IDE?


...and also welcome Adam! =)
0 Samiha Shaheed · January 21, 2015
Since this is the only forum where "arduino" was mentioned, and I am not allowed to create a forum yet, I am posting my question here.

I am doing my first Arduino project and faced with the following compiling error and do not know what to do! 



C:\Users\Samiha\AppData\Local\Temp\build3058240577403485459.tmp/core.a(main.cpp.o): In function `main':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:40: undefined reference to `setup'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `loop'
collect2: error: ld returned 1 exit status
Error compiling.


If anyone has any clue please HELP! Thank you in advance.
-2 Çağlan Turgut · September 7, 2014
Erm.... We are a small community..? :) Never thought that was gonna happen one day.:ermm:


Sorry, I don't know SQL:(
0 Adam Karrer · September 6, 2014
Thanks, guys!

I actually posted in the SQL forum and no one replied. :D Guess I'll have to do some more research or drop that idea and come up with a new one. 
+2 Çağlan Turgut · September 6, 2014
Welcome to the community! If you have any questions feel free to ask. I'm sure that someone will try to help you.
  • 1
  • 2

Introductions

107,282 followers
About

Just joined the website? Feel free to introduce yourself here. Oh, by the way, welcome to BuckysRoom!

Links
Moderators
Bucky Roberts Administrator