Flash

add news feed

post a story

Send to KindleWorking a lot with Raspberry Pi and Arduino stuff lately. The concept of pull-up and pull-down resistors came up quickly and confused me a little at first. So I thought I’d do a little demo of how they work and why th...
Send to KindleWorking a lot with Raspberry Pi and Arduino stuff lately. The concept of pull-up and pull-down resistors came up quickly and confused me a little at first. So I thought I’d do a little demo of how they work and why they are needed. Doing this helped to clarify it for me, so maybe it’ll help you too. Common scenario. You want to set up something that reads an input of a GPIO pin. Say, you want to know when the user is pressing a switch. You set up a simple circuit like so: When you press the button, pin 25 goes high. No press, no high, must be low, right? Well, let’s see… We’ll set up a simple Python script to read the status of pin 25: #! /usr/bin/python import RPi.GPIO as GPIO import time PIN = 25 GPIO.setmode(GPIO.BCM) GPIO.setup(PIN, GPIO.IN) while True: if GPIO.input(PIN) == GPIO.HIGH: print("pin is high") time.sleep(.1) else: print("pin is low") time.sleep(.1) When I run this, I get 20-30 lines saying pin 25 is high, then 20-30 saying it’s low, back and forth, without touching the button. Sure enough when I press the button, it stays high, but apparently the definition of “low” is not “not high”. After too many years in the highly binary world of software programming, some of us delving into hardware may be surprised to learn that a lot of electronics operate on “tri-state logic” as opposed to simple binary. Here, an input can be high, low, or floating. In this particular circuit, high means connected to 3.3 volts, low means connected to ground, and floating means… neither or somewhere in between. Actually, due to the sensitive nature of tiny electronics, system components can pick up various signals that create slight fluctuations in what it is reading. It’s rarely if ever going to pick up exactly 0.000 volts just because it’s not connected to 3.3 volts. So we need to force the issue and say, “Yo! You are LOW!” My first thought on how to do this would probably have been to do something like this: When the switch is in one position, pin 25 is connected directly to ground, sending it solidly low. When the switch is changed, it connects 25 to 3.3 volts, making it high. This will work just fine, but it’s a bit overengineered as it turns out. How about if we go simpler and just connect pin 25 to ground and leave it that way, like so: (Note: DO NOT ACTUALLY BUILD THIS CIRCUIT!) Now, when the switch is open, pin 25 is undoubtedly low. But we have a problem that when you do hit the switch, you now have a short circuit directly between 3.3 volts and ground. Not good. Again, do not do this. The solution? Throw a resistor in there: Now, when the switch is open, pin 25 is connected to ground through the 10K resistor. Even with the resistor though, it’s enough of a connection to make it solidly low. It’s not going to fluctuate. Then we hit the switch, connecting the lower part of the circuit to the 3.3 volts. Because we have a fairly high resistance there, most of the current is going to go to pin 25, sending it solidly high. Some of it is also going to go to ground via R1. But Ohm’s Law tells us that 3.3 volts divided by 10,000 ohms will let about 0.33 milliamps in. That’s not going to break the bank. So in this circuit, R1 is called a pull-down resistor because in its default state it pulls the signal down to 0 volts or a low state. Now let’s swap things around a bit: Now pin 25 is hard-wired to 3.3 volts through R1, making its default state high. However when the button is pressed, pin 25 will be directly connected to ground, sending it low. Because the resistor pulls pin 25 up to 3.3 volts and a high state, it’s now known as a pull-up resistor. So, which one do you use? It depends on whether you want your default signal to be high or low. Hope that helps. Send to Kindle
4 28 days ago
So as most of you know I have been doing Flash for a long time and recently I have been doing Unity3d (well mostly NGUI you could say). It has been mostly fun and mostly rigid. Rigid??? Yeah I would say rigid. Unity3d imposes you a way t...
So as most of you know I have been doing Flash for a long time and recently I have been doing Unity3d (well mostly NGUI you could say). It has been mostly fun and mostly rigid. Rigid??? Yeah I would say rigid. Unity3d imposes you a way to work that is mostly to use the editor and not programming. They really really want you to use the editor. And coming from Flash this feels really weird. Probably because after 6 years of using Flash you kinda learn that the most you can do in code, the better and easier it is. Also, if you constantly switch between the editor and the code, it gets confusing, always switching paradigms. GameObject for president! GameObject is the root of everything you do in Unity, but one of the most annoying thing is that you can’t extend GameObject… Come on, let me do it, just the tip . Here is what I would do if I could; I would make myself APIs for 2D. Moving something in x would be gameObject.x = 30; instead of gameObject.tranform.localPosition = new Vector3d (30,  gameObject.tranform.localPosition.y, gameObject.tranform.localPosition.z); Man have you seen the size of that thing just to move something in x???? Let me make it better for myself, I don’t care about 3D, I wouldn’t have a z value I would call it depth and it would make the code way more readable. Encapsulation, what encapsulation The other thing that bugs me is that to interact through code with a gameObject hierarchy you created, you basically have to know how it is built and you have to get your pieces using Find or GetComponent. Find statements are the ugliest ones as they use a string to get you what you want and is really error prone. So you add your Script to your gameObject (proof that the editor is taking precedence over code) but to have interactions between multiple gameObject you have to do it through their scripts which you have to know their types, but have no idea if they exist and are linked or not. You’ll know at runtime when the error pops up. Everything on a GameObject Basically my point here is that you can’t do anything if it ain’t on a gameObject. Some core functions just won’t work if it ain’t. Like the WWW function(used to load stuff from the web) (really cryptic name if you ask me). It won’t work if it ain’t called from a MonoBehavior and MonoBehaviors can’t be instantiated, it needs to be added to a GameObject. So what about Models, code that only keep the states of an application or that loads data to hold it. Models have nothing to do with GameObjects, they should be allowed to use the WWW function. But no, if you want to, you need to create a GameObject, add to it a loading script, and wait for it to pass you back the data. Doesn’t that sound devious to you? Let it define itself I like Unity3d; it allows you to build for Android / iOs very easily, but the way it is so rigid really annoys me. I think that a project that is so young like Unity3D should not force the users down some path, it should let them find incredible and unthought ways of using it. I want to do 2D / UI with it and right now it is pretty annoying to do so.
29 minutes ago
Learn how Scout processes data sent by Flash Player and Adobe AIR to display charts and graphs.
Learn how Scout processes data sent by Flash Player and Adobe AIR to display charts and graphs.
2 days ago
Look at some of the features and workflows that Edge Reflow CC offers.
Look at some of the features and workflows that Edge Reflow CC offers.
2 days ago
Look at some of the features and workflows that Edge Reflow CC offers.
Look at some of the features and workflows that Edge Reflow CC offers.
2 days ago
Build a simple mobile app with Dreamweaver, jQuery Mobile, and PhoneGap and package it with PhoneGap Build.
Build a simple mobile app with Dreamweaver, jQuery Mobile, and PhoneGap and package it with PhoneGap Build.
2 days ago
Learn about the next-generation profiler for Flash content running on both the desktop (Flash Player) and on mobile devices (Adobe AIR).
Learn about the next-generation profiler for Flash content running on both the desktop (Flash Player) and on mobile devices (Adobe AIR).
2 days ago
Learn how Flash Player manages its memory usage and how to understand the memory data in Scout.
Learn how Flash Player manages its memory usage and how to understand the memory data in Scout.
2 days ago
Découvrez la gestion de l’utilisation de la mémoire par Flash Player ainsi que les données de mémoire dans Scout.
Découvrez la gestion de l’utilisation de la mémoire par Flash Player ainsi que les données de mémoire dans Scout.
2 days ago
Add, style, and link to a second page for a website in Dreamweaver CS6.
Add, style, and link to a second page for a website in Dreamweaver CS6.
2 days ago