Programming Problemo

I was trying to make a simple circuit that when you hold the button a blue light turns on and when you let go a red light turns on for the same amount of seconds you held the button.
Intead the button does nothing, and both lights turn on and stay on forever. Can you help me?

If you post your program properly as described in "How to use this forum - please read" then we probably can help. But posting a picture of text is just silly.

Steve

One obvious problem, you are reading the input and storing it in the variable State, but using the variable Switch in the if statement. Switch was defined as a constant equal to 2, so (Switch == LOW) will always be false.

Suppose that the user of your useless system holds the switch down for 35 seconds. How long are the LEDs actually going to be on?

Look at the state change detection example to learn how PROPERLY time the interval between when a switch BECOMES pressed and when it BECOMES released.

Knowing how your switch is actually wired (the hard way) would be useful, too.

Thanks for the help, I got it to work now. I have another question, does the arduino IED use javascript or another programming language?

The .ino files of Arduino sketches are compiled as C++. You can write these files as pure C++ if you like and it will work fine. However, the Arduino IDE will automatically do a couple of things to your sketch if necessary that allow you to write code that is not exactly valid C++. The reason for this is to make it a bit easier for beginners with no prior programming experience to get started with Arduino.

This is what is done during the sketch preprocessing step of compilation:

  • If there are multiple .ino files in the sketch, concatenate them into a single file, starting with the file that matches the sketch folder name, followed by the rest in alphabetical order.
  • Add #include <Arduino.h> at the top of the file.
  • Insert automatically generated function prototypes for any function that doesn’t already have one.
  • Add #line directives to make warning/error messages still match the original sketch files.

Another difference you might notice between C++ and Arduino sketches is that Arduino sketches use setup() and loop() instead of main(). The main() function is still there, it’s just tucked away out of site in the core library. You can override the core library’s main() by defining your own in the sketch if you like.

Arduino’s stance is that these differences mean that there is an “Arduino Programming Language”. However, it’s important to understand that you can find a lot of useful information about C++ programming that applies perfectly to Arduino programming. You don’t need to restrict your searches for information to the “Arduino Programming Language”.

Sketch preprocessing is only done on the .ino files. If you add a tab to your sketch with the .cpp file extension, it will be compiled as C++. If you add a tab to your sketch with the .c file extension, it will be compiled as C. If you add a tab to your sketch with the .S file extension, it will be compiled as assembly.

The Arduino IDE itself is written in Java, but that has no relevance to the programming language used to write your sketches.

The Arduino IDE was originally based on the Processing IDE years ago. Processing is a language based on Java. The standard Arduino API was designed to be familiar to people working with Processing, so you might notice some similarities between Processing sketches and Arduino sketches, but they are written in two different languages.

does the arduino IED use javascript or another programming language?

There is no "arduino IED" so the question is moot.

The Arduino IDE is written in Java, but the Arduino is programmed in C++.

Considering what the acronym "IED" commonly refers to, I sure hope there won't be an "Arduino IED".

Now, if it stood for "inadvertent explosive device" instead, I may have once made one by changing power supplies without considering the rating of a tantalum capacitor on the breadboard.

pert:
The Arduino IDE was originally based on the Processing IDE years ago.

No mention of Wiring?

It's not relevant to the discussion.