View Full Version : How to use Xcode output signal to control LED light?
May 10, 2012, 11:43 AM
if i want to write a program to output signal to control relay or led.
how to write that?
did any reference books to recommend?
May 10, 2012, 02:23 PM
You'd need some sort of hardware interface. If you just want to generate a high/low signal, you can simply use a USB to serial adaptor, and set the DTR and RTS lines as needed. You could also read signals over the CD, DSR, CTS, and RI lines. This would give you 2 lines out and 4 in. I'm not sure how exactly to address the serial port in ObjC/Cocoa, but I'm certain there's a way, either via the built-in serial library or some third party library.
If you're looking to do something more complicated, or require more control lines, you might want to look into using an Arduino or similar microcontroller as your hardware interface. You could hook up your input/output lines (the Arduino Uno gives you a total of 20 I/O lines (although only 18 if you're controlling it via your computer) and if you need more you can always multiplex them via a shift register. You can either write your code directly to run on the Arduino, or set it up so it accepts commands from the computer to turn the pins on and off.
May 10, 2012, 06:02 PM
You can't use Xcode alone. You probably also need some extra hardware to talk to from the Mac (either USB, networked micro, or a PCI card). Then you need to find and read the reference for that particular item of external hardware to determine what API it requires to send it commands. Then you may also need to write code on some IDE other than Xcode to program that external hardware (if it's an arduino, beagleboard or rasberry pi, for instance).
May 10, 2012, 10:05 PM
Here's an article about not using Xcode:
It relies on CrossPack (AVR cross-compiler tools), Terminal.app, and make.
May 11, 2012, 02:28 AM
thanks for reply:D