Library and Strange Values

I’m brand new to Arduino and the forum here so please excuse any grievous errors I might make. I have 3 questions/problems.

  1. How can I edit, or even just view, libraries that other people have made? I have downloaded libraries and looked at examples, but I’d like to see the generated functions. Which file do I open up for this, the .cpp, the .h, or am I just completely off?

  2. I’ve started some simple RGB color mixing that fades LEDs in and out in succession (which produces some really nice purples when the red and blue mix). I’m trying to toggle it on and off with a simple push button. I think I’ve mostly gotten it (even though I did use a newbie “goto” statement) but it won’t seem to turn off when I tell it to because I’m getting some odd push button values. I put in some serial prints to get an idea of what was happening and here is what I got:
    “Before reading:
    0
    0
    After reading:
    1
    0”

So I’m getting a one for the button reading when the button isn’t pressed. I thought it was a timing issue so I added a delay before the read of the button. I’m just trying to get my head around the whole LOOP format of Arduino since I’m used to MatLab and VBA scripting.

  1. Finally, I was thinking is there a way to interrupt the LOOP so that no matter when the button is pressed it will stop? I vaguely read something about this, but not to much avail. Currently I’m just polling constantly to see if the button is pushed.

The code should ideally operate as such. The button is pressed–>the lights turn on do their cool strobe action–>the button is pressed again (whenever)–>the lights turn off.

Here’s the code:

//This is to play around with RGB color LEDs

//Setup Pin Colors
#define RLED 9
#define GLED 6
#define BLED 5
#define BUTTON 7

signed long count=0;
int pushval=0;
int old_pushval=0;
int Rval=0;
int Gval=0;
int Bval=0;
int val;

void setup()
{
  pinMode(RLED, OUTPUT);
  pinMode(GLED, OUTPUT);
  pinMode(BLED, OUTPUT);
  pinMode(BUTTON, INPUT);
  Serial.begin(9600);
}
void loop()
{
  Serial.println("Before reading:");
  Serial.println(pushval);
  Serial.println(old_pushval);
  pushval=digitalRead(BUTTON);
  Serial.println("After reading:");
  Serial.println(pushval);
  Serial.println(old_pushval);
  if((pushval==0) && (old_pushval==1)){ //reset
    Serial.println("reset");
    pushval=1;
    old_pushval=0;
  }
  Serial.println(pushval);
  Serial.println(old_pushval);
  if((pushval==1) && (old_pushval==0)){
    Serial.println("Initialized");
    Rval=255;
    Gval=0;
    Bval=0;
    analogWrite(BLED,Bval);
    for(Rval=255;Gval<255;){
      if(digitalRead(BUTTON)==HIGH){
        pushval=0;
        old_pushval=0;
        goto escape;
      }
      analogWrite(RLED, Rval);
      analogWrite(GLED, Gval);
      Rval=Rval-1;
      Gval=Gval+1;
      delay(2);
    }
    analogWrite(RLED,Rval);
    for(Gval=255; Bval<255;){
      if(digitalRead(BUTTON)==HIGH){
        pushval=0;
        old_pushval=0;
        goto escape;
      }
      analogWrite(GLED, Gval);
      analogWrite(BLED, Bval);
      Gval=Gval-1;
      Bval=Bval+1;
      delay(2);
    }
    analogWrite(GLED,Gval);
    for(Bval=255;Rval<255;){
      if(digitalRead(BUTTON)==HIGH){
        pushval=0;
        old_pushval=0;
        goto escape;
      }
      analogWrite(BLED, Bval);
      analogWrite(RLED, Rval);
      Bval=Bval-1;
      Rval=Rval+1;
      delay(2);
    }
    count=count+1;
    Serial.println(count);
  }

  old_pushval=pushval;

  escape:
    if(old_pushval==0&&pushval==0&&count>0){
      Serial.println("Escaped");
      Serial.println(pushval);
      Serial.println(old_pushval);
      val=0;
      analogWrite(RLED, val);
      analogWrite(BLED, val);
      analogWrite(GLED, val);
      count=0;
      delay(50);
    }
}

It’s really simple, I know, but I just got Arduino yesterday. Thanks for your help!

I'd like to see the generated functions

Not sure what you mean by "generated", but the source is in the .cpp files.

"goto" statment

Go to the naughty step, and don't leave until you have said that you're sorry, and that you won't use that word ever again.

All you have to remember about "loop" is that as soon as you return from it, either explicitly by executing a "return" or by falling through to the bottom of the function, is that "loop" is called again immediately.

If you want to stop, you have to put your own infinite loop inside "loop()", or do everything including your "stop" inside "setup".

I had been using "break" before. "return" makes much more sense. Hopefully Arduino can forgive me for making it "goto" somewhere.

And I can now read libraries.

Thanks a lot for the reply!