LED control on arduino with a app OS X in Swift

Hello people!


im learning swift. im trying to write a app for OS X in Swift. i want to control a LED on a arduino with my app on my OS X. I would like to do with to buttons, ON and OFF. The following Code:


import Cocoa

class ViewController: NSViewController {


@IBAction func ButtonOn(sender: NSButton) {

// LED On

let URLstring = "http:/192.168.100.50$1"

let URL = NSURL(string: URLstring)

let URLReq = NSURLRequest(URL: URL!)

}



@IBAction func ButtonOFF(sender: NSButton) {

//LED OFF

let URLstring = "http:/192.168.100.50$2"

let URL = NSURL(string: URLstring)

let URLReq = NSURLRequest(URL: URL!)

}


override func viewDidLoad() {

super.viewDidLoad()

/

}

override var representedObject: AnyObject? {

didSet {

/

}

}

}


Thank you!!

Answered by gita07 in 146005022

i found this code (https://www.youtube.com/watch?v=ECWn22zKRBA)in Objective-C for Iphone, i want to do something similar but for OS X.

Can someone help me?


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize myWebView;

- (void)viewDidLoad

{

[super viewDidLoad];

/

}

- (void)viewDidUnload

{

[self setMyWebView:nil];

[super viewDidUnload];

/

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

- (IBAction)switchPressed:(id)sender

{

UISwitch *theSwitch = (UISwitch *) sender;


if (theSwitch.isOn)

{

/

NSURL *url = [NSURL URLWithString:@"http:/

NSURLRequest *req = [NSURLRequest requestWithURL:url];

[myWebView loadRequest:req];

}

else

{

/

NSURL *url = [NSURL URLWithString:@"http:/

NSURLRequest *req = [NSURLRequest requestWithURL:url];

[myWebView loadRequest:req];

}

}

@end

Accepted Answer

i found this code (https://www.youtube.com/watch?v=ECWn22zKRBA)in Objective-C for Iphone, i want to do something similar but for OS X.

Can someone help me?


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize myWebView;

- (void)viewDidLoad

{

[super viewDidLoad];

/

}

- (void)viewDidUnload

{

[self setMyWebView:nil];

[super viewDidUnload];

/

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

- (IBAction)switchPressed:(id)sender

{

UISwitch *theSwitch = (UISwitch *) sender;


if (theSwitch.isOn)

{

/

NSURL *url = [NSURL URLWithString:@"http:/

NSURLRequest *req = [NSURLRequest requestWithURL:url];

[myWebView loadRequest:req];

}

else

{

/

NSURL *url = [NSURL URLWithString:@"http:/

NSURLRequest *req = [NSURLRequest requestWithURL:url];

[myWebView loadRequest:req];

}

}

@end

LED control on arduino with a app OS X in Swift
 
 
Q