ROBOTC.net forums
http://www.robotc.net/forums/

Mindsensors Magic Wand
http://www.robotc.net/forums/viewtopic.php?f=1&t=4714
Page 1 of 1

Author:  Spiked3 [ Sat Jul 28, 2012 4:47 pm ]
Post subject:  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

Author:  mightor [ Sun Jul 29, 2012 1:48 am ]
Post subject:  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

Author:  Spiked3 [ Sun Jul 29, 2012 2:57 am ]
Post subject:  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!

Author:  mightor [ Sun Jul 29, 2012 4:02 am ]
Post subject:  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 204 times
MSMW-driver.h [2.84 KiB]
Downloaded 205 times

Author:  Spiked3 [ Sun Jul 29, 2012 5:17 am ]
Post subject:  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);
        }

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/