Hello Pixel Blazers, long time user, not at all good at coding. I am a Burning Man artist and have prolly installed 25 Pixel Blazes over the last 3-4 years into various laser cut projects. This year I am helping a friend with a larger project. I have my pixelblaze all set up with an expansion board and I can see the Adafruit IR sensor functioning properly using the export var function.
export var analogInputs
//when the IR sensor is unblocked it returns a value of approx 0.500±
//when the IR sensor is blocked it returns a value of 0.000
What I am trying to do is when a participant fills out a piece of paper and slips it into a slot, the IR sensor detects the paper by crossing the beam path and the lights change to white flashing for 5 seconds, after 5 seconds the lights return to a simple rainbow pattern and thats it.
I started by reading throught the tutorials again and brushing up on my terrible coding skills, I’m more of a sound engineer and 4,000watt laser cutter user/Laser safety officer. You can see my latest project here www.ednatheelephant.com
I found some code online as a start point, and have been trying to edit the code to work with the
//export function analogInput on the A0 header on the expansion board.
I am using this tutorial as my base code and have been trying to edit to to work with what i need to do.
Instead of using buttons though I want to use the IR sensor Arduino | IR Breakbeam Sensors | Adafruit Learning System through the expansion board. (If that is what I should be doing)
Here is the code I am starting with, it obviously needs alot of adjustment just to get the analogInput to replace the button functions in this code, I have tried many changes to the code using the Editor and referring to the instructions in the editor and I’m not getting anywhere:
//
// Example of a momentary button connected to a GPIO pin
//
// Each time the button is pressed, the value of ‘buttonValue’
// should be 1
export var buttonValue // Use export to watch values in the PixelBlaze editor
var BUTTON_PIN = 26
pinMode(BUTTON_PIN, INPUT_PULLDOWN)
export function beforeRender(delta) {
buttonValue = digitalRead(BUTTON_PIN);
}
export function render(index) {
hsv(.0, 0, 0)
if (buttonValue == 1) {
hsv(.97, 1, 1) // Set color if
HERE IS THE CODE THAT I HAVE EDITED TO USE analogInputs BUT DON’T KNOW WHAT I AM DOING SO IT DOESN’T FUNCTION
export var analogInputs // Use export to watch values in the PixelBlaze editor
var BUTTON_PIN = 26 //Im sure this needs to be changed but not sure what to
analogRead(0) //this is the input I am using A0
export function beforeRender(delta) {
buttonValue = analogRead(0);
}
export function render(index) {
hsv(.97, 1, .2)
}
export function toggleTestButton(isEnabled){ //I added this to have a GUI button while testing
if (buttonValue == 1) {
hsv(.97, 1, 1) // Set color if button is pressed
}
}
Any help to guide me in making this work and teach me along the way would be amazing.
Thanks in advance, I feel like I’m starting to drop the ball on this project and don’t want to let down a big team of people putting the rest of this large art project together next week on the playa.