Arduino Lightsaber

billpealer:
i'll give it a try. can i rinse and repeat and do that for the swing sensor too? a different bool?

bool saber_is_on; ?

er...

does that go in the

int bool saber_is_on; portion above setup?

The "bool" key word declares a variable that can only have two values: "true" and "false". It's just like when you are declaring "int" variables that can hold integer values. In this case, you just want to know if the saber is on or not, so that can be used to keep track of it.

If that's too confusing, you can use "int" instead and just use the values 0 and 1 to mean false and true and do checks on that.

billpealer:
and why the 3 closed curly brackets? i see that from time to time, not quite sure wtf that is all about.
}
}
}

That has to do with defining blocks of code. For each "{", there must be a corresponding "}". This pattern is used all over the place in C and C++. For example, your if blocks will look like this:

if(saber_is_on)
{
//DO SOMETHING HERE
//DO SOMETHING ELSE HERE
//CODE, CODE, AND MORE CODE, etc.
}

But what if you want to check something else before you worry about if the saber is on? Well, then you'd create another if block around your first block. This is called "nesting", meaning one block is contained within another.

if(button_is_pressed)
{
if(saber_is_on)
{
//DO SOMETHING HERE
//DO SOMETHING ELSE HERE
//CODE, CODE, AND MORE CODE, etc.
} //This ends the saber_is_on list of actions
} //This ends the button_is_pressed list of actions

The "{" brackets allow you to define a list of actions to be performed without having to do the check again. The language lets you get away with not using them in the case that you only have one action to perform, but I always use the brackets even then because it makes the code more readable.