Tagline

The Studio of Eric Valosin

Tuesday, April 22, 2014

Arduino and LED's for Complete and Total Morons like Me

I've been working on a project using an Arduino to control RGB LED's with PWM and discovered there's a WHOLE TON of stuff people just assume you know. It took many hours to get the basic understanding to even know what to google. So here you go.

WHAT YOU NEED TO KNOW SO YOU DON'T MELT STUFF


First some clarification -

PWM, or Pulse Width Modulation means controlling the R, G, and B components of the LED values from 0-255 through digital output pins that tell it how frequently to turn on, giving the effect of dimming, fading, or being at partial brightness.)

Choosing your LED. I went with common Anode as opposed to common Cathode, so that's what this is written for. With common Anode, the long pin ("common") needs to be connected to the +Voltage, and the R,G,and B pins need to be connected to a resistor (to protect them) and then to the digital output pins of the Arduino. Then the LED lights up when pulled HIGH, which essentially means the PWM color scale goes from 0(fully on) to 255(fully off). This is counterintuitive, and you can easily fix your program by writing your color value "r" as "255-r"

Common Cathode are just the opposite - Common goes to Ground, not +5V, and it turns on when pulled LOW; PWM = 0(fully off) to 255(fully on).

OK NOW THEN...

First look at the LED's data sheet for two things - the Forward Voltage (Vf) and the Forward Current (If).

Forward Voltage is the amount the applied voltage drops when it passes through the LED. You'll need this to calculate how much resistance you need. For the sake of argument we'll say it's 3, but check your data sheet.

Forward Current is the amount of current (in mA) that each diode draws (remember RGB LEDs are actually 3 diodes in one, and each needs to be accounted for separately)

PROTECTING YOUR LEDS

If you don't want to blow out the LED, you need resistors connected to the R,G,and B pins. To figure this out, you first need to know how much voltage you plan on supplying. The typical Arduino supplies 5V, so we'll go with that, but this can be adjusted accordingly if, say, you're hooking it up to a 9V battery, etc.

1) Finding your Resistor with Ohm's Law - when solved for Resistance, Ohm's Law says the Resistance (R) you need in order to get the proper current at a given voltage is equal to the Voltage (V) divided by the Current (I).
R = V/I

Remember that you're supplying 5V, but there is a drop due to the LED's Forward Voltage. So, you must subtract the forward voltage from the total voltage
V = VDD - Vf
in this case V = 5 - 3
V = 2

So, R = 2/I
I is in this case 20mA (or .02A)
so R = 2/.02
R = 100 ohms (shown as Ω)

So you need to connect your LED's terminal to a Resistor of at least 100 Ω so that when it draws the 20mA of current it doesn't blow itself up. Always round up if you land on a value that's not a common resistor value.

2) JUST in case, you should also make sure the resistor is the right Wattage (usually they come in 1/4W, 1/6W, 1/8W, etc), using the following formula:

Power (P) = Current(I) Squared times Resistance (R) [pardon my lack of superscript and subscript... blogger and I are fighting right now]
we now know the resistance is 100, so in this case
P = .02squared x 100
P = .04

Since 1/8W (.125) is well above .04, you should be fine with pretty much whatever you choose, but just pick one that's higher than the value of P so that you don't overheat the resistor.


Series or Parallel?
Single color LEDs can be wired in series, meaning the anode of one is connected directly to the cathode of the next and so on, and they can all share one resistor. However this is not possible with RGB LEDs since they share a common pin between the three colors. They must be wired in parallel, meaning each LED is connected directly to the power source and ground, rather than to each other. Every pin therefore needs its own resistor or else you'll end up with inconsistent color and insufficient protection.

- LED's wired in Series share the same amount of current but multiply the amount of voltage per LED.
- LEDs in Parallel are the opposite, they all share the same Voltage but the current is multiplied per LED.

SO, if you have 5 LEDs in series, each wanting 3V and 20mA, you'll need to provide 15V (3V x 5 LEDs) and 20mA.
If you have 5 LEDs in parallel, each wanting 3V and 20mA, you'll need to provide 3V and 100mA (20mA x 5 LEDs)

PROTECTING YOUR ARDUINO

We're not commonly told this, but the Arduino pins can only take so much power. I'm using the Arduino Uno, so if your model differs, this is stuff you'll want to google. In general, try googling things like "Arduino max voltage" or "arduino [insert name of pin here] max current"

Check here for starters - You'll definitely want to google these limitations for yourself. EVERY PIN ON THE ARDUINO has its limitations. Don't just take my word for it. My bad memory or misread data sheet, or incomplete information here is not worth your fried arduino pin.

It naturally supplies 5V, but can handle up to about 12V using the power barrel plug thingy (a technical term). Don't exceed that unless you like the smell of burning electronics. That power can be converted to 5V with the +5V pin, or sent straight through the Vin pin. Each of these pins can handle only so much current running through them

+5V pin = max 450mA - 600mA current depending on power source
Vin pin = max 1A current

Then you need to know how much the output pins you're using can take. These are the ones you really want to pay attention to:

Digital I/O pin = max 40mA current
total max current from all I/O pins combined = 200mA

This means that any given output pin can actually only support 2 LEDs in parallel at full brightness without risking damage! ...whoops.

MOSFETs for More Power...
Clearly there is an way you can still hook up more LEDs, but you'll want to look into an external power supply if the voltage or current demands get too big for the V pins, as well as something to isolate the output pins from the massive current being drawn by the LEDs

I recommend n-channel MOSFET transistors (see here for a great reference article by Adafruit), which can handle up to 16A and essentially acts like a switch that passes the higher current straight from a power supply to the LED to ground without ever touching the Arduino, whenever it's "gate" is triggered by a smaller current sent from the Arduino I/O pin. Here's a great MOSFET tutorial

The MOSFET has a "gate" "source" and "drain." I won't go into why here, but suffice it to say that to drive a common anode LED with a MOSFET you should connect the following:

Gate --  to the digital I/O pin that sends color/PWM signal
Source -- to the LED leg that corresponds with the arduino output pin
Drain -- to ground 

Then you can connect each leg of the LED to it's own MOSFET (using 3 MOSFETS, one for each color - you don't need one for each LED, all of the red LED terminals can be connected to the red MOSFET and so on) and the common Anode to the high-current power source!

For added protection, you should have a low value resistor between the gate and the pin (lots of argument on exactly how low since the current is not consistent, but I've seen between 100 and 330Ω recommended), as well as high value (pull-down) resistor connecting Gate to Drain, essentially to prevent things from going the wrong way inside (I've seen 1k, 10k, and 100k recommended).

A PWM side note: I still don't quite understand why, but the n-channel MOSFET inverts the voltage applied to it. So, remember before that we had to write our "r" value as "255-r" to get it to cooperate with common anode? well now it gets inverted back, so you can leave it as good ol' "r" (as if you were coding for a common cathode LED. Don't change the wiring though...)

I think that about covers it, and I hope this is helpful! Good luck to you as you try to light stuff up without blowing it up!






Monday, April 21, 2014

Good Grief: An Easter Crisis, Mindfulness and the Absolute

EASTER
- this profoundly joyous time of resurrection - is not time of the year I expected to grieve. Holy week has passed, yet I find myself returning to an empty tomb to weep a bit. I grieve not the loss of a person right now, but of an ideology I didn't know I had.

Disclaimer: If you're looking for fully digested philosophical treatises or flashy epiphanic discoveries, this is not that type of post. I do those every now and then, but the conclusion of this Lenten season and the arrival of Easter has left me in a far messier, unresolved place - albeit, a good one I think. This is one of those posts where I crack my heart open a bit and pour out the contents, partially grasping at cathartic straws, and partially because I know I'm not alone in my quandaries. I share these here because I know that the outcomes of these sorts of struggles have everything to do with my work as an artist and thinker, and, more directly, with the way I live my life in a public manner. This is going to be a long post, and you're lucky it has any organizational strategy at all.

A Look Back at Lent

These past 46 days my church, under the leadership my wife, its Pastor, embarked on a theme of repentance and reconciliation - reconciliation with nature, diverse people groups, within families, the church community, the self, and of course reconciliation with God. Each week focused on a different topic and provided tools for recognizing how we as individuals and as a community have fallen short of right relationship, and how we might reconcile those relationships in our daily lives.

I personally took this opportunity to invest in some reconciliatory practices of self-care, since the rigors of grad school had pretty much undone most of my better habits in this respect. I took up daily mindfulness practices (daily is a very generous description, but at least a good start), tried to eat better (embarking on a 30 day smoothie challenge that tasted great but ended up making my wife sick), and exercised more regularly (again a generous description, but a good start). I also tried to very intentionally reconnect with my family and take time away from the workaholism instilled in me through grad school under threat of career death. It's been a far more difficult task than I expected, but one that I think made me more prepared for and receptive to the this upcoming crisis of faith.

Resurrection Reconciliation

Today my wife gave one of the most brilliant Easter sermons I've ever heard. That's not me being biased, that's me being blown away. Having heard and thought deeply about the Easter story over and over again, I was not expecting to hear it in a fresh way that clicked any differently than it had in the past. Yet, it left me in tears and got me thinking new, deep thoughts. I tried recounting the sermon's brilliance to a coworker today and failed miserably, so I'll spare you my troubled synopsis. Instead, suffice it here to discuss this one main point of hers:

Matthew 28:1-10, Jesus appears to the two Marys who had just discovered his empty tomb and the angel. The resurrected Christ says to the women "Greetings, do not be afraid. Go and tell my brothers to go to Galilee; there they will meet me." What we often overlook is that he does not call them his disciples, or even his friends, he calls them his brothers. These are the same "brothers" that within the last week had fallen asleep on him 3 times while he went through a point of crisis and begged them to stay awake with him, ran away when the authorities came, denied ever knowing him at all, and then stood and watched him get killed. That would be no friend of mine, much less a brother! Yet, as if it never happened, he greets them as beloved family.

The model of repentance and reconciliation gets flipped on its head. In every other case we studied, first you repent (acknowledge a wrong behavior and apologize) and then reconcile (reconnect and establish a better relationship). But here reconciliation is offered... and there seems to be no sign of repentance. At least not yet. These "brothers" had never so much as said they were sorry. But Jesus extends to them his familial love. He simply wants to see them again in Galilee.

The whole Easter story - in fact the whole of the Good News - is simply that. That even though we sometimes don't take God seriously and "fall asleep" on him, even though we put on our blinders and flee the scene in favor of our own agendas and self-preservation, even when we deny the intimacy we may have had with God for fear of rejection or persecution, even when we stand idly by as we watch our strained faith die... God choses to take no offense, calls us "brother" and "sister" and simply longs to see us again in Galilee. That had me in tears, and I even choke up a bit typing it. This is God's Easter Basket to us - a gift of guilt-free reconciliation undeservedly given.

I don't easily tear up, so that's usually an indication I've got some major crap going on behind the scenes that I'm not aware of. So I began digging. It's not a new message; why did it goad me so much this time?

Clinging to the Absolute

For a long time I've been obsessed with a search for absolute truth. I know, I know. The good postmodernist in me knows that there's either no such thing, or that if there is we simply have no access to it, mired in our relative subjectivity. But that hasn't stopped me from seeking it. I don't want an absolute in the Platonic ideal sense; there are too many terrible ethical implications like an inherent intolerance of diversity. However, if the absolute dies entirely, then where's the anchor of our faith? Wheres the logic of metaphysics? How do we not get lost in a relativistic ethical free-for-all? (Many of these I address in my thesis monograph, seeking a relational metaphysics).

Relational models of truth are the immediate answer, and for this reason non-anthropomorphic ideas of God have become very popular, since they sidestep the problems of correspondent truth and allow for more theological adaptability. I don't disagree with these ideas (in fact I cringe at the anthropomorphized God we create in our image rather than the other way around), but I am wary of the pantheism that can result. As a result, I clung desperately to the idea of some absolute truth that might one day disclose itself in some unfathomable, ineffable way.

Without knowing it, this for me took the form of Heaven. By this I mean eternal life - eternal union with a pure sense of deity outside of the constraints of our individual contexts (no time, space, physical bodily limitations, etc). I may have no access to absolute truth in this life, but at least I can bank on becoming one with the absolute once I'm outside of this earthly mixture of complications (ab-solute).

I had never realized it, but this focus on heaven shifted my entire paradigm in a very particular way:

A Crisis of Options

This is the classic tug of war between the subjective and the absolute, the immanent and the transcendent, the temporal and the eternal, the kingdom on earth and the kingdom of heaven.

Assuming for the sake of argument that there is indeed both this life and eternal life in one form or another, I began to realize there are 4 ways of navigating these realities.

1) put all your focus on this life and completely ignore eternity
2) put an equal importance on both and focus more on this life since it's all we have access to right now
3) put an equal importance on both and focus more on eternity since that is the goal to be striven towards
4) put all your focus on eternity and completely ignore this life.

...I wonder if there's a 5th way, putting equal importance on both but focusing on neither - maybe that's the more apophatic approach, but I'm not sure yet what that looks like...

(Of course you can put no importance on either and become a nihilist, but then why bother writing this at all?)

1 and 4 seem irresponsible and implausible, so I was left with 2 options, and it became clear to me that my bias towards the absolute had me subtly leaning toward option 3 (we'll call the "heaven-focused" option), focusing my life around eternity, rather than the here and now; all my works on earth - though supremely valuable - are an attempt to live in a way that grows out of my respect for eternity and the eternally transcendent God's commands. I discovered my wife, as it turns out, leans more toward option 2 (we'll call it the "world-focused" option), living in the here-and-now so that all her works are an attempt to participate with an immanent God in the time we have, bringing eternity and the kingdom of God to the present.

The increasing implausibility of a dogmatically prescribed anthropomorphic God - and don't misunderstand me, I'd want nothing other than an implausible God, for there could be no God that is entirely plausible; I seek to unknown this God all the time - has inevitably got me questioning my most basic pre-assumptions, even down to the very existence of God. So, I examined each scenario and what you're left with if you then ask if God really exists.

After I had worn down the tolerance of my wife's patient ear, I began scribbling down my thoughts in a flow chart.

The conclusions in the flow chart from left to right if you can't read my handwriting:
"is your focus on this life or the next?" ->
this life -> yes -> "sweet, you lived well and get to enjoy heaven as a side benefit"
this life -> no -> "oh well, you tried your best, but at least this life was lived well"
next life -> yes -> "you must take God's instructions for life seriously and act in this life accordingly"
next life -> no -> "everything is meaningless" (and not in the Ecclesiastical sense)
To my horror, my wife's world-focused viewpoint was pretty much a win-win situation, while my heaven-focused one logically terminates, at best, in business as usual, and at worst nihilism! My gut said her way was clearly the better approach. As I recount it now, it seems obvious that a focus on the present is in fact the way of mindfulness and relationality, while a focus on heaven the way of idealism and fundamentalist evangelicals. That should have been my first red flag as I seek to be neither of the latter two, but then again I've always been a recovering idealist at heart.

The Grieving Process

So why, then, if it is so painfully clear that I should release my grasp on the absolute and be focusing elsewhere, do I feel so reluctant to do so?

Then it hit me. Grace. My wife's sermon illustrated grace - undeserved reconciliation even before repentance takes place. I've always believed in this grace, but that was actually the problem. Real grace is a hard thing to swallow, especially when you know you don't deserve it, and my eternally-focused viewpoint allowed me to hide from the painful reality that I'm not pulling my weight here on earth and the humiliating feeling of receiving something so beyond my deserving (also therefore missing the incomprehensible grandeur of the true grace that God offers). Grace in this heaven-focused paradigm is watered down to a mere shadow of itself, for the full gravity of it is logically inconsistent in that setting. For this reason, life took on a subtle meaninglessness, leaving me only the absolute to cling to. Allow me to explain:

If live rightly at an 80% capacity, let's say God's grace covers that 20% failure and gets me into heaven. I appreciate that greatly, but since the real goal is heaven anyway, I appreciate it only in the sense that God has picked up my tab, so to speak. The fact that the finite world is 20% short of being a better place doesn't really matter much in an eternal sense. This makes complacency easy, and sincere repentance (that should follow the undeserved reconciliation) very hard.

However, with a world-focused spiritual paradigm, that 20% failure in the world really matters. Now, not only is grace picking up my tab and getting me into a heaven I don't deserve, it is also God forgiving the personal affront of my complacency in the one area that really matters. Thinking that my main goal in the universe has been handed to me and it is only a secondary task that is 80% complete is palatable. However, realizing that my main purpose in the universe and God's top priority for me is only 80% complete when I could have easily striven for 100% pains me greatly. Getting into Heaven would happen anyway. That's grace, and that's up to God. But the one part that really matters, that was really up to me, I blew. Ouch. 

That's why I clung to the absolute. It let me justify mediocrity and complacency. It let me pretend I don't actually have to go out and feed the hungry, donate a liver, or what have you, to bring the kingdom of God on earth no matter the personal cost. It let me stay numb and never have to truly repent.

Resolution

I now see, for the first time, the true importance of mindfulness. I now see, for the first time, the real value of relational truth. I now repent, for the first time, more earnestly for I am utterly ashamed and horrified at my satisfaction with 80%.

Over the coming weeks I'll be reevaluating a lot of lifestyle habits and ideologies, weighing them against this new paradigm shift, and making sure that the implications of my artwork support this new worldview (I suspect it has in fact led me here and supported it all along, and it is only now that I'm catching up with it, but it can't hurt to double-check).

And so I feel like I've been led by the hand of the resurrected Christ back to the empty tomb in order to lay down my idealistic tendencies towards the absolute. They must be buried there so that I can rise to a fuller eternity, one that encompasses the here and now in its breadth. Does the absolute still exist? It very well may (in fact I think it does), but it cannot be my primary focus. I feel like my wife was Mary in the story, passing along Jesus' greeting to me on the street. I for one am eager to meet him in Galilee.

If you've read this entire post, first of all, God bless your tenacity! (I'd apologize for the time you've lost reading it, but frankly look at how much time I spent writing it!) I can only hope it has been edifying to you in some way. Secondly, I urge you to think deeply about the logical conclusions implicit in your own most basic pre-assumptions, whatever they may be, and take a good hard look at the way you live in response to that. Lastly, I sincerely hope you discover the joy of this world so that you might have both this world and the next to their fullest, being reconciled to the great Creator in unfathomable ways.

Peace, Introspection, and Easter Baskets,
- Eric

Wednesday, March 26, 2014

On Mindfulness: Detachment, Social Justice, and Meeting God

As I've embarked on a Lenten quest to reacquaint myself with practices of spiritual and physical self-care, I've taken up an experiment in mindfulness. As I heard testimonies to its mental health benefits and recounted my own previous successes, I began pondering why mere mindfulness (watching your own thoughts) should lead to overall calmness and assurance at all. (For a great video on mindfulness meditation that sparked this all, see my G+ post here [if that doesn't work, see the original post here]) As a relative novice in the field, I'd love to hear any thiughts of those more deeply entrenched in contemplative practices. However, neophyte that I am, I had a simple epiphany: it occurred to me that mindfulness transforms us because it is an exercise of acceptance.

At least in my case (and in others, I've been told), eventually one finds that it's nearly impossible to truly control or empty all your thoughts. And so it becomes less an exercise of control and more one of learning to embrace a certain lack of it (which paradoxically is a major gain of it). When we recognize we cannot control that which we feel like we most aught to be able to (our own thoughts), we by necessity begin to watch, accept, and even love their uncontrollable eccentricities. How much more then will that attitude translate to things over which we already know we have little control anyway (events, people, and circumstances outside our minds). The internal dialogue translates to a general, external attitude of radical acceptance.

This is the "detachment" (abgescheidenheit) mystics like Meister Eckhart preached, or the detachment (gelassenheit) Martin Heidegger said allows things to even show up as things at all, phenomenologically. It's not a lack of love or passion for things, but a rather a true acceptance of things as they are, even when we can't control them; even when they happen to be in our own mind. Detachment from control, judgment, and preconception, to simply let things be things.

So what of social activism? Does this acceptance mean we can't change things? Can't right injustices? Far from it. It means our actions are fueled not out of bitterness and disgust (contempt for a thing as it is), but out of hope and love for what could be (acceptance of a thing and it's potentials). We see a wrong, accept it as what it is (a wrong), also accepting our own emotions and desires as what they are, and then choose our actions in order that the thing as it is might become a better thing. It's a delicate distinction that gives a sort of meta-level perspective that should allow us to operate from a more rational, patient, assured, persistent place (especially as it helps us accept our own shortcomings as we try and fail and try again; as one Zen master put it, even repeatedly failing to have a Zen experience can be a Zen experience!). It is in this way that Eckhart asserts that Contemplation is not a quiet, static, internal state but a lively, active event that permeates our daily lives.

This, by the way, is the only way to truly encounter God in any mystical sense - for only when we accept God for what God is - on God's own terms - letting God be God (even when that's unfathomable and uncontrollable), will God show up as God at all.

Friday, March 21, 2014

LED Cross Fade

As I've been working on my computer meditation for() loop project, the next step was to get the LED colors to fade from one to the next, rather than snapping right from one color to the other. This seemed like it should be really simple, but it proved to be rather challenging. Getting each color of the RGB LED to transition simultaneously, and at a controllable speed was the tricky part. (getting them to transition one after another was not too hard).

I looked online and couldn't find much of use that was versatile enough, except for this Arduino example which frankly just seemed way more complicated than it needed to be. However, I was able to use it as a template to create a much more concise version that allows the user to input not only the starting and ending colors, but also the duration and smoothness of the fade. I hope this is helpful to anyone who might be looking for something similar...

(Scroll to the bottom of the post for code you can copy and paste. If that's not working for whatever reason, you can find it here)

In the mean time...

A nice little package fortuitously arrived at my doorstep yesterday
So... I upped my pushbutton prayer bead prototype (see my prior posts in the link above if that makes no sense to you) to include 5 buttons, confirming that the process used to coordinate 2 and 3 buttons will work indefinitely!

Thursday, March 20, 2014

Pushbutton Progress

I've made a few more advances in my pushbutton prayer beads project. (follow it from the beginning here) When last I posted, I left with a few lingering questions - the first of which was how to highlight the pixel on the reference image that was being displayed in the right hand image and LED. I managed (with some more complex algebra than I was expecting to have to use) to write a formula that would convert the selected pixel's location in the pixel array to it's actual x and y coordinates in the image itself. Then I multiplied those figures (to scale up the pixelated image to the size of the output window) and drew a box around that resized pixel in yellow. After some quick troubleshooting and reformulating, I got the box to sync up with the LED and pixel:



The second question was how to daisy-chain the pushbuttons together. In my prayer bead string of buttons, I wanted to be able to differentiate between having hit the same button twice and moving to the next button in the sequence. My solution was to make two strings of buttons ending in two input pins and then alternate the button strings so that the inputs would sequentially alternate. For this I assumed I had to use Normally Closed buttons, since the circuit would have to run all the way to the last button in the sequence and be broken by any of them along the way.

I didn't have any NC buttons, so I decided to make my own (a circuit closed temporarily by a movable conductive object), but my breadboard was occupied by my other prototypes. That's when I remembered that graphite is conductive! Who needs breadboards?


As I was trying things out, I discovered that the legs directly across from each other on the Normally Open pushbuttons I had were actually completed circuits, and that pushing the button would actually connect the two parallel sets of legs to each other, which means that I can link the NO buttons to each other after all without worrying about the circuit being constantly broken. It's like railroad tracks; the two parallel tracks just don't connect until any one of the buttons is pressed (and lays down a cross tie? Ok, no more railroad metaphors.) Here's my drawn graphite prototype in action.


Then I translated that to my breadboarded prototype, and we have our first chain of buttons (both doing the same thing to control the LED). I lastly took that one step further and wrote the code to accommodate 3 buttons in a series, alternating the two circuits, and accounting for whether the current button pressed is part of circuit 1 or 2. This way, the pixel is only advanced if the button pressed is the next button in the series. If the user presses the same button twice it merely repeats that same pixel.
[pic of breadboard]



notice the tiny yellow square highlighting the pixel in the pink ring towards the top left quadrant of the image
See the next bit of progress here...

Tuesday, March 11, 2014

En-light-ening Imagery.

Some more progress on my Pushbutton Prayer Bead For() Loop Computer Meditation project.


(lightspeed recap [pardon the pun]: a for() loop is like the meditative rosary prayer of a computer. I'm trying to make prayer beads where each bead is a pushbutton that "meditates" on the color of a pixel in an image, looping through the whole image in a sort of computerized rosary prayer, and filling the room with that color as you go)

I've successfully translated my pushbutton LED color test sketch from Arduino to Processing (using the Arduino/Firmata library), which means I can start playing around with the visual display and image control alongside the hardware input/output.

My original plan was to use pushbuttons to control the color of the light in a room through the use of LEDs, but it suddenly occurred to me... I may not even need a bazillion LED's like I feared (though I might go that route anyway). I could theoretically output the color to a processing display window that is merely flooded into the room via digital projection instead of physical lights. The only hang up would be networking multiple projectors if one doesn't cut it, which I don't quite know about yet. Stuff to ponder...

...but in any case...

I can now control both the color of the LED and the color of the "pixel" on the screen by use of the pushbutton switch (cycling between 3 colors - I chose red green and blue for ease of troubleshooting)



Next, to make it cycle through the actual colors of the pixels in an image instead of pre-chosen colors. for this test, I chose a 100x100px thumbnail of my Meditation 1.1 drawing, and wrote a code to manually loop through every pixel (replicating the automated process of a for() loop), advancing one pixel every time the button is pressed. The RGB of that pixel then gets output to the "pixel" on the right side of the screen and the LED (though they all look slightly bluish in this video).


In my next studio session with this project I'll be looking to somehow highlight on the leftmost image what pixel is being displayed, and then maybe play around with easing in/out of the color (rather than it disappearing suddenly when the button is released).


Getting there, slowly but surely!

Go to my Next post for this project

Tuesday, March 4, 2014

How Computers Meditate: A New Project

For() Loop Meditation

In programming, a "for loop" is a way of performing an operation on a series of items. For example, looking at every individual pixel of an image, one after another, and doing something to each of them. It goes something like this:

for(x=0; x<100; x++) {
    pixels[x] = color(255);
}


Transliterated to english: 

for every integer (starting with 0; and going up to 100; incrementing 1 after each time) {
    look at the corresponding pixel assigned to [that integer] and set = it's color (to white);
}

To look through a whole image, you'd have to include the y dimension as well as the x, but you get the idea: You look at a pixel, do something to it, move on to the next pixel and repeat until you reach the end. The more I thought about this, the more I felt like the computer program was almost meditating, completing a mantra, repeated for every pixel it looped through... a for() loop is a computer meditating!

Now then, for a temporary non-sequitor: 

I took a trip to the Rubin Museum, where they had an exhibit of Tibetan Prayer Beads, and began studying the theory behind them - why 108 beads, how they're used, what materials amplify prayers to what degree, etc. I'll share a bit of their enlightenment with you:




...and suddenly it hit me! It occured to me that the "meditation" of the for loop is essentially a rosary prayer! As you move from bead to bead you complete the same prayer for each bead until you reach the end.

Imagine:

for(bead=0; bead<108; bead++){
    sayPrayer();
}


Pushbutton Prayer Beads


I wondered if there could be a way to meditate on an image, pixel by pixel, by using "prayer beads" made of pushbuttons. Every bead's button advances you to the next pixel. Perhaps the room even fills with light the color of that pixel when you press the button. Even more, maybe that pixel then gets assigned a random size and location on a wall and gets projected into a random collage, reconfiguring the image (starting to tap into the mystical, apophatic deconstruction of the image - knowing it less as you know it more...). Maybe the image in question is even derived from a live snapshot of the viewer himself...

My naive pre-prototype (and much pre-studying) sketches and notes:





Pushbutton Prototypes


For the end result, since I will want the signal to run through the chain of buttons to whatever button in the series happens to trigger the change, I'm guessing I'll probably want NC pushbuttons (Normally Closed; pressing them breaks the circuit) instead of the standard NO (Normally Open; pressing them completes the circuit). Otherwise the circuit will always be broken by all the buttons except the one in play. Don't have any of those right now though, so I decided to get started with some very basic pushbutton prototypes.

1) I started off with the prebaked arduino pushbutton tutorial. Two pushbuttons are set to input pins (2 and 3 in this case) that tell an LED (set to the standard output pin 13) to turn on if one button is pressed but not if both are pressed.





2) Using a microcontroller for this seemed like overkill, but it afforded me the opportunity to learn about pull-up resistors and other stuff that will come in handy when its no longer overkill later. But I wanted to see if I could back up a bit and do the simpler task: prove my understanding of the circuitry by bypassing the microcontroller. So I made a simple pushbutton circuit (hooked up to a battery instead) that would turn the LED on if the button was pressed. No fancy logic statements for the coordination of two buttons, but it worked, so I felt reassured about moving on!

technically I really don't know if the resistor used is the appropriate strength. I didn't do the math (nor claim to really understand how to... Ohms law is still a hypothesis in my mind...) but I know LEDs can handle a range of voltage so I wasn't too worried about blowing it out.


And of course my wife just informed me this was all stuff she learned in high school science (I blame a new system in middle school that placed me in the wrong math track for the rest of my academic career)! Well, better I catch up now then! (For the record, I know this stuff is elementary and did learn it quite early on. I think it's the practical application I missed out on)

3) Now to see if I can write a sketch to control the color of an RGB LED and cycle through the colors based on the push of a button. First, a sketch equivalent to the first one controlling the red LED, but where each RGB value could be manually input.



4) Finally, modifying that sketch so that the RGB values are indexed as options of a switch case function, and each button press cycles through those options. Here I selected 3 random color combinations to cycle through.

Added a switch case with 3 possible RGB values, and then a Button State Change function that switches between case options whenever the button is first pressed.

Hopefully these are the beginning steps to then populating that list of possible colors from the pixels of an image, and then stringing enough lights together for a big effect, and enough buttons together for prayer beads! To be continued