Attached is a simple project for a flasher for a motorcycle. It does verify but something was wrong with declaring some of the variables. I made it work but Im not sure I got them in the right place.
flasherState and interval were coming up as " not declared " when I had them in the set up section, but were ok when I moved them into the loop section.
It verifies now so I guess it's ok, then?
ppuxley:
flasherState and interval were coming up as " not declared " when I had them in the set up section, but were ok when I moved them into the loop section.
It verifies now so I guess it's ok, then?
Variables that are declared in a function, like setup() or loop() are only visible inside that function. So a variable declared in setup() won't be visible to the code in loop().
If you need both functions to see those variables, declaring them as global (so putting them at the top of the code, above setup(), for example) is one way to do that. For example:
ppuxley:
flasherState and interval were coming up as " not declared " when I had them in the set up section, but were ok when I moved them into the loop section.
It verifies now so I guess it's ok, then?
The compiler can only spot syntactical errors (deviations from the syntax of the C language). It can't "understand" your code. So you can't ever depend on it to validate your code.
Project built today on the bread board and working well with a pro mini. I had the interval calculation incorrect to obtain the requisite 60 to 120 flashes per minute.
Next will be to try with a smaller board, I'm thinking of a Digispark so that with a Songle relay the whole thing can be packaged up quite small.
The Digispark has an onboard 500mA 5v regulator. The relay coil draws about 80mA, the sensor only about 4mA, so should be able to cope.
Also I think I can feed it directly with 12v and do away with the external 5V regulator.
They say Power via USB or External Source - 5v or 7-35v (12v or less recommended, automatic selection) On-board 500ma 5V Regulator
Any problems with that?