Code and circuit from today’s lecture

//
// Stay on Table example for MSP430G2553 / MSP430G2452
// Written by Ted Burke - Last modified 22-3-2017
//
// P1.1 = Colour sensor input - low on black, high on white
// P2.0 = LED
// P2.1 = LM forward
// P2.2 = LM reverse
// P2.3 = RM forward
// P2.4 = RM reverse
//

#include <msp430.h>
  
void main( void )
{
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
      
    P1DIR = 0b00000000; // P1.1 is colour sensor
    P2DIR = 0b00011111; // P2.0 is LED, P2.1-4 are motors
    
    // Main loop repeats forever
    while(1)
    {
        if (P1IN & BIT1)
        {
            // white detected
            P2OUT = 0b00010010;
        }
        else
        {
            // black detected
            P2OUT = 0b00001011;
        }
    }
}
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s