DF Robot Beetle Microcontroller - RGB LED not working properly with LeonardoCode

Hi, I am currently working on a project with the DF Robot Beetle and my LED is not working properly and I don't know why. Here is my code -

#include <CapacitiveSensor.h>
CapacitiveSensor Sensor = CapacitiveSensor(A0, A1);
long val;
int redPin = 9;
int greenPin = 10;
int bluePin = 11;

void setup()
{
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
val = Sensor.capacitiveSensor(30);
Serial.println(val);
if(val >= 1000) {
function1();
}
else if (val == 0) {
function2();
}
}

void function1(){

if (val >= 1000)
{
digitalWrite(bluePin, HIGH);
delay(500);
digitalWrite(bluePin, LOW);
}

}

void function2(){

if (val <= 100)
{
digitalWrite(redPin, HIGH);
delay(500);
digitalWrite(redPin, LOW);
}

}

I use "val" as a serial number to keep track of if the mechanical switch I am using is turning off or on to turn my LED on or off. However, when "var" is over 1000, "on", my RGB LED turn from purple to white in a blinking fashion, and when "var" equals 0, "off", the LED becomes a static blue, when the code says it should be red. I my microcontroller broken? I do not know what to do, any ideas?

Please fix your post above. There should be code tags, a schematic and links to the specs of components you are using. What you have posted so far is not enough for us to understand why it is going wrong, we can only guess.