This program is the first program written for the PIC32 micr
This program is the first program written for the PIC32 microcontroller(DiGILENT MX7). This program waits for BTN1 to be pressed and then it cycles through lighting the 4 on board LEDs until BTN1 is pressed again. Now i have done the LED part. What i need is I need to set the button1 to turn on/off the lighting. This program should be written in C language. Please help me as soon as possible. Thank you.
#include <plib.h>
#pragma config ICESEL = ICS_PGx1
#pragma config FNOSC = PRIPLL
#pragma config POSCMOD = EC
#pragma config FPLLIDIV = DIV_2
#pragma config FPLLMUL = MUL_20
#pragma config FPLLODIV = DIV_1
#pragma config FPBDIV = DIV_8
#define delay_count 200000
unsigned int tcfg;
int counter = 0;
void main(void){
PORTSetPinsDigitalOut(IOPORT_G, BIT_12 | BIT_13 | BIT_14 | BIT_15); //BIT_12/13/14/15 is LED 1/2/3/4
PORTSetPinsDigitalIn(IOPORT_G, BIT_6); //BIT_6 is button 1
PORTClearBits(IOPORT_G, BIT_12 | BIT_13 | BIT_14 | BIT_15);
//(int) bit = PORTReadBits(IOPORT_G, BIT_6);
counter = 0;
while(1){
PORTWrite (IOPORT_G, BIT_12);
for (counter = 0; counter < delay_count; counter++){}
PORTClearBits (IOPORT_G, BIT_12 | BIT_13 | BIT_14 | BIT_15);
for (counter = 0; counter < delay_count; counter++){}
PORTWrite (IOPORT_G, BIT_13);
for (counter = 0; counter < delay_count; counter++){}
PORTClearBits (IOPORT_G, BIT_12 | BIT_13 | BIT_14 | BIT_15);
for (counter = 0; counter < delay_count; counter++){}
PORTWrite (IOPORT_G, BIT_14);
for (counter = 0; counter < delay_count; counter++){}
PORTClearBits (IOPORT_G, BIT_12 | BIT_13 | BIT_14 | BIT_15);
for (counter = 0; counter < delay_count; counter++){}
PORTWrite (IOPORT_G, BIT_15);
for (counter = 0; counter < delay_count; counter++){}
PORTClearBits (IOPORT_G, BIT_12 | BIT_13 | BIT_14 | BIT_15);
for (counter = 0; counter < delay_count; counter++){}
}
}
Solution
#!/usr/bin/env python3 # Above line is needed so program can be run from Brickman # Plug a touch sensor into any sensor port from ev3dev.ev3 import * ts = TouchSensor() while True: if ts.value()==1: #touch sensor pressed Leds.set_color(Leds.LEFT, Leds.RED) else: Leds.set_color(Leds.LEFT, Leds.GREEN)