RGB lab interrupt pin / 4 types of
//Use Hardware-Debounced Switch to Control Interrupt
//Button pins
const int BUTTON_INT =1; //Interrupt 1 (pin 3 on the Uno)
const int RED =11; //Red LED on pin 11
const int GREEN =10; //Green LED on pin 10
const int BLUE =9; //Blue LED on pin 9
//Volatile variables can change inside interrupts
volatile int selectedLED = RED;
void setup()
{
pinMode (RED, OUTPUT);
pinMode (GREEN, OUTPUT);
pinMode (BLUE, OUTPUT);
//The pin is inverted, so we want to look at the rising edge
attachInterrupt(BUTTON_INT, swap, RISING);
}
void swap()
{
//Turn off the current LED
analogWrite(selectedLED, 0);
//Then, choose a new one.
if (selectedLED == GREEN)
selectedLED = RED;
else if (selectedLED == RED)
selectedLED = BLUE;
else if (selectedLED == BLUE)
selectedLED = GREEN;
}
void loop()
{
for (int i = 0; i<256; i++)
{
analogWrite(selectedLED, i);
delay(10);
}
for (int i = 255; i>= 0; i--)
{
analogWrite(selectedLED, i);
delay(10);
}
}
//Button pins
const int BUTTON_INT =1; //Interrupt 1 (pin 3 on the Uno)
const int RED =11; //Red LED on pin 11
const int GREEN =10; //Green LED on pin 10
const int BLUE =9; //Blue LED on pin 9
//Volatile variables can change inside interrupts
volatile int selectedLED = RED;
void setup()
{
pinMode (RED, OUTPUT);
pinMode (GREEN, OUTPUT);
pinMode (BLUE, OUTPUT);
//The pin is inverted, so we want to look at the rising edge
attachInterrupt(BUTTON_INT, swap, RISING);
}
void swap()
{
//Turn off the current LED
analogWrite(selectedLED, 0);
//Then, choose a new one.
if (selectedLED == GREEN)
selectedLED = RED;
else if (selectedLED == RED)
selectedLED = BLUE;
else if (selectedLED == BLUE)
selectedLED = GREEN;
}
void loop()
{
for (int i = 0; i<256; i++)
{
analogWrite(selectedLED, i);
delay(10);
}
for (int i = 255; i>= 0; i--)
{
analogWrite(selectedLED, i);
delay(10);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// need to fix bugs
// This program determines the maximum contiguous
// memory allocation that can be reserved during a
//specific program execution.
#include <stdio.h>
#include <stdlib.h>
#define UNIT 1000
int main(void)
{
// Declare and initialize variables.
int k=1, *ptr;
// Find maximum amount of contiguous memory
// available in units of millions of integers.
ptr = (int *)malloc(UNIT*sizeof(int));
while (ptr != NULL)
{
free(ptr);
k++;
ptr = (int *)malloc(k*UNIT*sizeof(int));
printf("%d integers \n",(k-1)*UNIT);
}
// Print maximum amount of memory available.
printf("Maximum contiguous memory available: /n");
printf("%k integers /n",(k-1)*UNIT);
// Exit program.
return 0;
}
// need to fix bugs
// This program determines the maximum contiguous
// memory allocation that can be reserved during a
//specific program execution.
#include <stdio.h>
#include <stdlib.h>
#define UNIT 1000
int main(void)
{
// Declare and initialize variables.
int k=1, *ptr;
// Find maximum amount of contiguous memory
// available in units of millions of integers.
ptr = (int *)malloc(UNIT*sizeof(int));
while (ptr != NULL)
{
free(ptr);
k++;
ptr = (int *)malloc(k*UNIT*sizeof(int));
printf("%d integers \n",(k-1)*UNIT);
}
// Print maximum amount of memory available.
printf("Maximum contiguous memory available: /n");
printf("%k integers /n",(k-1)*UNIT);
// Exit program.
return 0;
}
Comments
Post a Comment