im just trying to figure out how to control one section of 3 leds to just stay one color and change with a push button or turning a pot and have a off position thats it. can anyone help me with this please. I tried using the switching method but it wont work it only changes on one end of the pot for a small area.
this is what i have so far
/******************** (C) COPYRIGHT 2012 RadioSHack ********************
* File Name : strip.pde
* Author : TRS
* Version : V1.0
* Date : 27/04/2012
* Description : Main program body
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, RS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#include <avr/pgmspace.h>
// ******** DEBUG ==== should auto config to adapt different mother board *********
//#define DATA_1 (PORTF |= 0X01) // DATA 1 // for ATMEGA
//#define DATA_0 (PORTF &= 0XFE) // DATA 0 // for ATMEGA
//#define STRIP_PINOUT DDRF=0xFF // for ATMEGA
#define DATA_1 (PORTC |= 0X01) // DATA 1 // for UNO
#define DATA_0 (PORTC &= 0XFE) // DATA 0 // for UNO
#define STRIP_PINOUT (DDRC=0xFF) // for UNO
PROGMEM const unsigned long pattern_test_red[10][10]={
{0x0000ff}
};
PROGMEM const unsigned long pattern_test_blue[10][10]={
{0x00ff00}
};
PROGMEM const unsigned long pattern_test_green[10][10]={
{0xff0000}
};
const int analogInPin = A1; // Analog input pin that the potentiometer is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output for color
// ***********************************************************************************************************
// *
// * Power Up Init.
// *
// *
// ***********************************************************************************************************
void setup() {
STRIP_PINOUT; // set output pin - DEBUG: should auto detect which mother board for use
reset_strip();
//noInterrupts();
}
// ***********************************************************************************************************
// *
// * Main Loop
// *
// *
// ***********************************************************************************************************
void loop()
{
// read the analog in value:
int sensorValue = analogRead(analogInPin);
// map it to the range of 8 colors:
int outputValue = map(sensorValue, 0, 1023, 0, 3);
switch (outputValue) {
//off
case 0:
send_1M_pattern(pattern_test_red, 1, 10);
break;
//red
case 1:
send_1M_pattern(pattern_test_green, 1, 10);
break;
//yellow
case 2:
send_1M_pattern(pattern_test_blue, 1, 10);
break;
//green
case 3:
send_1M_pattern(pattern_test_red, 1, 10);
break;
}
/*
frame++;
if(frame<=10) LEDSTRIP_PATTERN_0();
if(10<frame<=20) LEDSTRIP_PATTERN_0();
if(20<frame<=30) LEDSTRIP_PATTERN_0();
if(frame>30) frame=1;
*/
//delay(1);
}
/*******************************************************************************
* Function Name : send_1M_pattern
* Description : Transmit pattern to whole 1 meter strip
*
* Input : pointer to ROM pattern; pattern length; frame rate
*
* Output : None
* Return : None
*******************************************************************************/
void send_1M_pattern(const unsigned long data[][10], int pattern_no, int frame_rate)
{
int i=0;
int j=0;
uint32_t temp_data;
for (i=0;i<pattern_no;i++)
{
noInterrupts();
for (j=0;j<10;j++)
{
temp_data=pgm_read_dword_near(&data[i][j]);
send_strip(temp_data);
}
interrupts();
delay(frame_rate);
}
}
/*******************************************************************************
* Function Name : send_strip
* Description : Transmit 24 pulse to LED strip
*
* Input : 24-bit data for the strip
*
* Output : None
* Return : None
*******************************************************************************/
void send_strip(uint32_t data)
{
int i;
unsigned long j=0x800000;
for (i=0;i<24;i++)
{
if (data & j)
{
DATA_1;
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
DATA_0;
}
else
{
DATA_1;
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
DATA_0;
}
j>>=1;
}
}
/*******************************************************************************
* Function Name : reset_strip
* Description : Send reset pulse to reset all color of the strip
*
* Input : None
*
* Output : None
* Return : None
*******************************************************************************/
void reset_strip()
{
DATA_0;
delayMicroseconds(20);
}