Saturday, January 30, 2010

Setting and clearing individual digital channels

Setting and clearing individual channels is straightforward - the appropriate functions take a value between 1 and 8 for output numbers 1-8 (as marked on the board).

Functions used:
  • SetDigitalChannel(int)
  • ClearDigitalChannel(int)


The program is built in the same way as before, but this time we'll have a Knight-Rider style progression of the LEDs

#include <iostream>
#include <time.h>
#include "K8055D_C.h"

using namespace std;


int main(void) {


    OpenDevice(0);        // select device #0

// Knight Rider 1            
    ClearAllDigital();        // set all digital outputs to off
    for (int b=0;b<5;b++){
        for (int a=1;a<9;a++){
            SetDigitalChannel(a);    // set individual digital channel
            cout << "Setting channel (incrementing) "<<a<<endl;
            Sleep(100);
            ClearDigitalChannel(a);    // clear individual digital channel
        }
        for (int a=7;a>1;a--){
            SetDigitalChannel(a);    // set individual digital channel
            cout << "Setting channel (incrementing) "<<a<<endl;
            Sleep(100);
            ClearDigitalChannel(a);    // clear individual digital channel
        }
    }
    ClearAllDigital();        // set all digital outputs to off

    
    CloseDevice();        // close device
    return 0;

}

No comments:

Post a Comment