|
Page 1 of 1
|
[ 5 posts ] |
|
| Author |
Message |
|
Spiked3
Expert
Joined: Tue Feb 28, 2012 3:10 pm Posts: 195
|
 Mindsensors Magic Wand
I don't know how many use the magic wand as a mobile debugging device. I do, and I saw one of Xander's videos where he also did. So I'll post some code I used for it, to get feedback (and point out mistakes), and for anyone to use if desired. After not bit manipulating for many years, it took a few tries   |  |  |  | Code: #ifndef __MSMW_H__ #define __MSMW_H__
#pragma systemFile
//**********************************************************// //* *// //* Magic Wand *// //* *// //**********************************************************//
// Xander Soldaat's driver suite #include "drivers/PCF8574-driver.h" // mindsensors magic wand
void MWsetLED(short ledToChange, bool on) { ubyte c; PCF8574readBytes(MAGICWAND, c); PCF8574sendBytes(MAGICWAND, (on ? c & ~(1 << ledToChange) : c | (1 << ledToChange)) ); }
void MWtoggleLED(short ledToChange) { ubyte c; PCF8574readBytes(MAGICWAND, c); PCF8574sendBytes(MAGICWAND, c ^ (1 << ledToChange)); }
void MWflashAndClear(int count) { int countr = 0; PCF8574sendBytes(MAGICWAND, 0xff); // all off while (countr++ < count) { for (int i = 0; i < 8; i++) { MWsetLED(i, true); wait1Msec(30); } for (int i = 0; i < 8; i++) { MWsetLED(i, false); wait1Msec(30); } PCF8574sendBytes(MAGICWAND, 0xff); // should not be needed, but just in case } }
#endif
|  |  |  |  |
_________________Mike aka Spiked3 http://www.spiked3.com
|
| Sat Jul 28, 2012 4:47 pm |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2905 Location: Rotterdam, The Netherlands
|
 Re: Mindsensors Magic Wand
Hey Spiked,
Would you mind if I added this to my driver suite? The only change I'll make is rename the functions to MSMW and add some Doxygen comments.
- Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Sun Jul 29, 2012 1:48 am |
|
 |
|
Spiked3
Expert
Joined: Tue Feb 28, 2012 3:10 pm Posts: 195
|
 Re: Mindsensors Magic Wand
I was hoping you would ask  Please do, no credit needed. And thank you a ton for your excellent library!
_________________Mike aka Spiked3 http://www.spiked3.com
|
| Sun Jul 29, 2012 2:57 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2905 Location: Rotterdam, The Netherlands
|
 Re: Mindsensors Magic Wand
Hey Mike,
I've attached the modified driver + demo program. Let me know what you think.
- Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Sun Jul 29, 2012 4:02 am |
|
 |
|
Spiked3
Expert
Joined: Tue Feb 28, 2012 3:10 pm Posts: 195
|
 Re: Mindsensors Magic Wand
Except for the extra braces on ifs with only one statement, beautiful  JK. for peace of mind, I added this to the test;
_________________Mike aka Spiked3 http://www.spiked3.com
|
| Sun Jul 29, 2012 5:17 am |
|
|
|
Page 1 of 1
|
[ 5 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 4 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|