void setup() 
{
    /* set up pins */
    pinMode(CALIB_SWITCH, INPUT);
    pinMode(BOT_SWITCH,   INPUT);

    pinMode(RED_LED,      OUTPUT);
    pinMode(YELLOW_LED,   OUTPUT);
    pinMode(GREEN_LED,    OUTPUT);
    pinMode(BLUE_LED,     OUTPUT);

    Serial.begin(9600);

    setupPhotosensor();
    setupMotorControl();
    setupCollision();
    setupCommunication();
}
void of3dLevelScene::setup()
{
    if(level.loadModel(getName() + ".dae")) {
        level.setRotation(0, 180, 1, 0, 0);
    }
    
    setupCollision();
    
    // fog
    GLfloat fogCol[4] = {0,0,0.5,1.f};
    glFogi(GL_FOG_MODE, 1); // exp2
    glFogfv(GL_FOG_COLOR, fogCol);
    glFogf(GL_FOG_DENSITY, 0.02f);
    glFogf(GL_FOG_START, 10.f);
    glFogf(GL_FOG_END, 300.f);
    
    cam.setup();
    cam.setNearClip(1.0f);
    cam.setPosition(0,6.f,-10.f);
    cam.lookAt(ofVec3f(0,0,100),ofVec3f(0,1,0));
    cam.setFov(38.f);
    cam.usemouse = false;
//    cam.enableOrtho();
    
    ofEnableAlphaBlending();
    ofEnableLighting();
    ofEnableDepthTest();
    
    // lighting
    light.setPosition(0, 400, 20);
    light.setDiffuseColor(ofFloatColor(0.95,1.0,1.0));
    light.enable();
    light.setParent(cam);
    
    // gui
    gui = new ofxUICanvas();
    gui->setFont("GUI/DejaVuSans.ttf");
    gui->setColorBack(ofColor(0,0,0,0));
    
    float guiWidth = 512.f;
    gameOverLose = new ofImage("GUI/game-over-lose.png");
    gameOverWin = new ofImage("GUI/game-over-win.png");
    gameOverImage = gui->addImage("game_over", gameOverLose, 512,128);
    okButton = gui->addImageButton("OK", "GUI/ok-btn.png", true, 256, 64);
    // center horizontally
    okButton->getRect()->setX(gameOverImage->getRect()->getHalfWidth() - okButton->getRect()->getHalfWidth());
    gui->autoSizeToFitWidgets();
    // center horizontally
    gui->setPosition(ofGetWidth()/2 - gui->getRect()->getHalfWidth(),
                     ofGetHeight()/2 - gui->getRect()->getHalfHeight());
    ofAddListener(gui->newGUIEvent, this, &of3dLevelScene::guiEvent);
    
    gui->setVisible(false);
    gui->setAutoDraw(false);
    
    // effects
    post.init(ofGetWidth(),ofGetHeight());
    post.createPass<BloomPass>()->setEnabled(true);
    convolutionPass = post.createPass<ConvolutionPass>();
    convolutionPass->setEnabled(false);

    // player
    player = new ofPlayer();
    
    backgroundMusic.loadSound("ludumdare29.mp3");
    backgroundMusic.setVolume(0.7);
    backgroundMusic.setLoop(true);
    backgroundMusic.play();
    
    // load level
    load();
}