View unanswered posts | View active topics It is currently Sun Aug 31, 2014 12:42 am






Reply to topic  [ 5 posts ] 
Mindsensors Magic Wand 
Author Message
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3203
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Jul 29, 2012 1:48 am
Profile WWW
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Mindsensors Magic Wand
I was hoping you would ask :P 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3203
Location: Rotterdam, The Netherlands
Post Re: Mindsensors Magic Wand
Hey Mike,

I've attached the modified driver + demo program. Let me know what you think.

- Xander


Attachments:
MSMW-test1.c [1.73 KiB]
Downloaded 83 times
MSMW-driver.h [2.84 KiB]
Downloaded 86 times

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]
Sun Jul 29, 2012 4:02 am
Profile WWW
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post 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;
Code:
// make sure it works without bothering other LEDS
        for (int j = 1; j < 10; j++)
        {
            int r = random(7);
            MSMWsetLED(MAGICWAND, r, true);
            for (int i = 0; i < 10; i++)
            {
                MSMWtoggleLED(MAGICWAND, 4);
                wait1Msec(200);
            }
            MSMWsetLED(MAGICWAND, r, false);
        }

_________________
Mike aka Spiked3
http://www.spiked3.com


Sun Jul 29, 2012 5:17 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.