Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: "Growing" pixels with Neopixel Strip on: December 04, 2013, 07:00:47 pm
Quote
Any thoughts? Thanks!
It looks to me like strip.setPixelColor(i, Co); sets the color of the ith pixel. It should be trivial to determine the value of i, based on the number of pixels in your strip, so that you can set whichever pixels you like on or off or whatever color you like.

This actually helps alot! Although, I do not know what Co is. I've got my middle and end LED's constantly lit, now I have to figure out how I would go about adding and subtracting LEDs when I spin the pot. Hmm.
2  Using Arduino / Programming Questions / "Growing" pixels with Neopixel Strip on: December 04, 2013, 05:14:21 pm
So I just received my 60 led Neopixel Strip, and I've been messing around with the code. I'm not too familiar with the Neopixel library, so I was wondering if you guys might be able to help me out. What I'm trying to do, is have 4 pixels constantly lit in the center of the strip and 2 pixels constantly lit on either end of the strip. Using a potentiometer, I want to be able to make the center strip increase in size out to either end of the strip. I've found a piece of code on the internet that bounces a led segment back and fourth between the two ends of the strip. I figured this would be a good place to start. I just have to figure out how to make the segment stationary at the start, then be able to build towards the ends. This should be an easy fix, but I haven't played with Arduino in a little while and I'm not sure where to go from here.

Code:
//NeoPixel LED Digital Strip Cylon Eye v1.10 Created by EternalCore
#include <Adafruit_NeoPixel.h>

//Settings:
#define PIN 6 //The Pin out your Neopixel DIN strip/stick is connected to (Default is 6)
#define TPIXEL 60 //The total amount of pixel's/led's in your connected strip/stick (Default is 60)
int wait_T=40; //This is the delay between moving back and forth and per pixel
int PixelCount=60; //Set this to the AMOUNT of Led's/Pixels you have or want to use on your strip And It can be used to tell where to Stop then return the eye at in the strip
int Pixel_Start_End=0; //Set this to where you want it to Start/End at
boolean UsingBar = false; //Set this to true If you are using the 8x1 Neopixel Bar Or you want to only use 3 leds for the scanner.

Adafruit_NeoPixel strip = Adafruit_NeoPixel(TPIXEL, PIN, NEO_GRB + NEO_KHZ800); //Standered Strip function

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  //Serial.begin(9600); //Used For pixel Count Debugging
}
void loop() {
  //Example: CylonEyeUp(Center_Dot_Color, Second_Dot_color, Third_Dot_color, wait_T, PixelCount, Pixel_Start_End);
  CylonEyeUp(strip.Color(175,0,0), strip.Color(25,0,0), strip.Color(10,0,0), wait_T, PixelCount, Pixel_Start_End);
  delay(wait_T);
  //Example: CylonEyeDown(Center_Dot_Color, Second_Dot_color, Third_Dot_color, wait_T, PixelCount, Pixel_Start_End);
  CylonEyeDown(strip.Color(175,0,0), strip.Color(25,0,0), strip.Color(10,0,0), wait_T, PixelCount, Pixel_Start_End);
  delay(wait_T);
}

void CylonEyeUp(uint32_t Co, uint32_t Ct, uint32_t Ctt, uint8_t Delay, int TotalPixels, int pStart) {
  for(int i=pStart; i<TotalPixels; i++) {
    if(!UsingBar) { strip.setPixelColor(i+2, Ctt); } //Third Dot Color
    strip.setPixelColor(i+1, Ct);   //Second Dot Color
    strip.setPixelColor(i, Co);     //Center Dot Color
    strip.setPixelColor(i-1, Ct);   //Second Dot Color
    if(!UsingBar) { strip.setPixelColor(i-2, Ctt); } //Third Dot Color

    if(!UsingBar) {
      strip.setPixelColor(i-3, strip.Color(0,0,0)); //Clears the dots after the 3rd color
    } else {
      strip.setPixelColor(i-2, strip.Color(0,0,0)); //Clears the dots after the 2rd color
    }
    strip.show();
    //Serial.println(i); //Used For pixel Count Debugging
    delay(Delay);
  }
}
void CylonEyeDown(uint32_t Co, uint32_t Ct, uint32_t Ctt, uint8_t Delay, int TotalPixels, int pEnd) {
  for(int i=TotalPixels-1; i>pEnd; i--) {
    if(!UsingBar) { strip.setPixelColor(i-2, Ctt); } //Third Dot Color
    strip.setPixelColor(i-1, Ct);   //Second Dot Color
    strip.setPixelColor(i, Co);    //Center Dot Color
    strip.setPixelColor(i+1, Ct);  //Second Dot Color
    if(!UsingBar) { strip.setPixelColor(i+2, Ctt); } //Third Dot Color

    if(!UsingBar) {
      strip.setPixelColor(i+3, strip.Color(0,0,0)); //Clears the dots after the 3rd color
    } else {
      strip.setPixelColor(i+2, strip.Color(0,0,0)); //Clears the dots after the 2rd color
    }
    strip.show();
    //Serial.println(i); //Used For pixel Count Debugging
    delay(Delay);
  }
}

Any thoughts? Thanks!
3  Using Arduino / Programming Questions / arduino midi code for a simple keyboard on: March 24, 2012, 01:39:15 pm
so i got a grant from my school to do a project involving arduino, midi, and some fsrs. being a music major, i'm not too familiar with arduino yet so i could use some help with the code. the premise here is there are 12 fsrs on a pair of gloves (1 on each of the ten fingers and 1 at the base of each palm). these fsrs are hooked up to a arduino mega with a sparkfun midi shield mounted on it. then, using 4 pairs of infrared emitters and receivers, i'm going to have these positioned by the feet so that when a particular beam is broken, the octave of the notes in the hands switches, either up or down. (no beams being broken is the middle c octave, the two pairs of ir detectors to the right make the octaves go up and the 2 left pair go down). so i have a couple of codes that i've found, one for the shield on sparkfun and the other is a combination of a code i found online and stuff from my arduino cookbook. any help would be appreciated, especially with changing octaves with the emitter/receivers!

Code:
// SparkFun MIDI Sheild and MIDI Breakout test code
// Defines bare-bones routines for sending and receiving MIDI data
// Written 02/16/10


// defines for MIDI Shield components only
#define KNOB1  0
#define KNOB2  1

#define BUTTON1  2
#define BUTTON2  3
#define BUTTON3  4

#define STAT1  7
#define STAT2  6

#define OFF 1
#define ON 2
#define WAIT 3

byte incomingByte;
byte note;
byte velocity;
int pot;

byte byte1;
byte byte2;
byte byte3;

int action=2; //1 =note off ; 2=note on ; 3= wait



void setup() {

  pinMode(STAT1,OUTPUT);  
  pinMode(STAT2,OUTPUT);

  pinMode(BUTTON1,INPUT);
  pinMode(BUTTON2,INPUT);
  pinMode(BUTTON3,INPUT);

  digitalWrite(BUTTON1,HIGH);
  digitalWrite(BUTTON2,HIGH);
  digitalWrite(BUTTON3,HIGH);

  for(int i = 0;i < 10;i++) // flash MIDI Sheild LED's on startup
  {
    digitalWrite(STAT1,HIGH);  
    digitalWrite(STAT2,LOW);
    delay(30);
    digitalWrite(STAT1,LOW);  
    digitalWrite(STAT2,HIGH);
    delay(30);
  }
  digitalWrite(STAT1,HIGH);  
  digitalWrite(STAT2,HIGH);

  //start serial with midi baudrate 31250
  Serial.begin(31250);    
}

void loop () {

  //*************** MIDI OUT ***************//

  pot = analogRead(0);
  note = pot/8;  // convert value to value 0-127
  if(button(BUTTON1) || button(BUTTON2) || button(BUTTON3))
  {  
    Midi_Send(0x90,note,0x45);
    while(button(BUTTON1) || button(BUTTON2) || button(BUTTON3));
  }

  //*************** MIDI LOOPBACK ******************//
  if(Serial.available() > 0)
  {
    byte1 = Serial.read();
    byte2 = Serial.read();
    byte3 = Serial.read();

    Midi_Send(byte1, byte2, byte3);
  }

  //*************** MIDI IN ***************//
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // wait for as status-byte, channel 1, note on or off
    if (incomingByte== 144) // Note on
    {
      action = OFF;
    }
    else if (incomingByte== 128) // Note off
    {
      action = ON;
    }
    else if (note==0 && action != WAIT) // note on, wait for note value
    {
      note=incomingByte;
    }
    else if (note!=0 && action != WAIT)  // velocity
    {
      velocity=incomingByte;
      if(action == ON){
        Midi_Send(0x90,note,velocity);
      }
      if(action == OFF){
        Midi_Send(0x80,note,velocity);
      }
      note=0;
      velocity=0;
      action=WAIT;
    }
    else{
    }
  }

}

void Midi_Send(byte cmd, byte data1, byte data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}

void blink(){
  digitalWrite(STAT1, HIGH);
  delay(100);
  digitalWrite(STAT1, LOW);
  delay(100);
}

char button(char button_num)
{
  return (!(digitalRead(button_num)));
}

Code:
const int middleC = 60;    // Middle C (MIDI note value 60) is the lowest note we'll play
 byte note = 0;              // The MIDI note value to be played
 int fsrAnalogPinC = 0;       // FSR is connected to analog 0
 int fsrReadingC;             // the analog reading from the FSR resistor divider
 int AnalogValue = 0;        // value from the analog input
 int lastNotePlayed = 0;     // note turned on when you press the switch
 int lastSwitchState = 0;    // state of the switch during previous time through the main loop
 //int currentSwitchState = 0;

 void setup() {
   //  Set MIDI baud rate:
   Serial.begin(31250);
 }

 void loop() {
   //  My potentiometer gave a range from 0 to 1023:
   AnalogValue = analogRead(0); //not correct, should be digital
   //  convert to a range from 0 to 127:
   note = AnalogValue/8; //same, digital
  
   fsrReadingC = analogRead(fsrAnalogPinC);
   // Check to see that the switch is pressed:
   if (fsrReadingC >= 1) {
     //  check to see that the switch wasn't pressed last time
     //  through the main loop:
     if (lastSwitchState == 0) {
       // set the note value based on the analog value, plus a couple octaves:
       // note = note + 60;
       // start a note playing:
       noteOn(0x90, note, 0x40);
       // save the note we played, so we can turn it off:
       lastNotePlayed = note;
     }
   }
   else {   // if the switch is not pressed:
     //  but the switch was pressed last time through the main loop:
     if (lastSwitchState == 1) {
       //  stop the last note played:
       noteOn(0x90, lastNotePlayed, 0x00);
     }
   }

   //  save the state of the switch for next time
   //  through the main loop:
   lastSwitchState = fsrReadingC;
 }

 //  plays a MIDI note.  Doesn't check to see that
 //  cmd is greater than 127, or that data values are  less than 127:
 void noteOn(byte cmd, byte pitch, byte velocity {
   Serial.print(cmd, BYTE);
   Serial.print(pitch, BYTE);
   Serial.print(velocity, BYTE);
 }

i only started with one fsr here to testing, but there should eventually be 12.

thanks guys.

4  Using Arduino / Programming Questions / Re: Using two FSRs on a timer to switch videos on: March 21, 2012, 06:49:20 pm
i need to make an if statement in processing that says something along the lines of, if timer ends + cup fsr activated, play good video, if timer ends + cup fsr not activated, play bad video. i just don't know how i would go about doing that.
5  Using Arduino / Programming Questions / Re: Using two FSRs on a timer to switch videos on: March 21, 2012, 06:44:28 pm
any suggestions then?
6  Using Arduino / Programming Questions / Using two FSRs on a timer to switch videos on: March 21, 2012, 06:17:14 pm
The premise here is, if you hit a golf ball, a FSR on the head of the club starts a timer. If within say, 5 seconds, FSR in the cup does not register the ball has gone in it, a video will play telling you "Keep practicing!", ect. I'm having a bit of trouble with the code, especially on the processing side. Any help would be appreciated.

Arduino
Code:
const int clubPin = A0;     
const int cupPin = A1; 

void setup()
{
   Serial.begin(9600);
}

void loop()
{
   int valclub = map(analogRead(clubPin), 0, 1023, 0, 255);
   Serial.println(valclub);
   delay(10);
   int valcup = map(analogRead(cupPin), 0, 1023, 0, 255);
   Serial.println(valcup);
   delay(10);
}

Processing
Code:
import processing.serial.*;
import processing.video.*;
 
float clubValue = 0;        // red value
float cupValue = 0;      // green value
 
Serial myPort;
 
Movie goodOne, goodTwo, goodThree, goodFour, goodFive, goodSix, goodSeven, goodEight, goodNine, goodTen, goodEleven, goodTwelve, goodThirteen, goodFourteen, goodFifteen, goodSixteen, goodSeventeen, badOne, badTwo, badThree, badFour, badFive, badSix, badSeven, badEight, badNine, badTen, badEleven, badTwelve, badThirteen, badFourteen, badFifteen, badSixteen, badSeventeen, badEighteen, badNineteen, badTwenty, badTwentyone, badTwentytwo, badTwentythree, badTwentyfour, badTwentyfive;

void setup() {

  size(1280, 720);
 
  goodOne = new Movie(this, "goodOne.mp4");
  goodTwo = new Movie(this, "goodTwo.mp4");
  goodThree = new Movie(this, "goodThree.mp4");
  goodFour = new Movie(this, "goodFour.mp4");
  goodFive = new Movie(this, "goodFive.mp4");
  goodSix = new Movie(this, "goodSix.mp4");
  goodSeven = new Movie(this, "goodSeven.mp4");
  goodEight = new Movie(this, "goodEight.mp4");
  goodNine = new Movie(this, "goodNine.mp4");
  goodTen = new Movie(this, "goodTen.mp4");
  goodEleven = new Movie(this, "goodEleven.mp4");
  goodTwelve = new Movie(this, "goodTwelve.mp4");
  goodThirteen = new Movie(this, "goodThirteen.mp4");
  goodFourteen = new Movie(this, "goodFourteen.mp4");
  goodFifteen = new Movie(this, "goodFifteen.mp4");
  goodSixteen = new Movie(this, "goodSixteen.mp4");
  goodSeventeen = new Movie(this, "goodSeventeen.mp4");
  badOne = new Movie(this, "badOne.mp4");
  badTwo = new Movie(this, "badTwo.mp4");
  badThree = new Movie(this, "badThree.mp4");
  badFour = new Movie(this, "badFour.mp4");
  badFive = new Movie(this, "badFive.mp4");
  badSix = new Movie(this, "badSix.mp4");
  badSeven = new Movie(this, "badSeven.mp4");
  badEight = new Movie(this, "badEight.mp4");
  badNine = new Movie(this, "badNine.mp4");
  badTen = new Movie(this, "badTen.mp4");
  badEleven = new Movie(this, "badEleven.mp4");
  badTwelve = new Movie(this, "badTwelve.mp4");
  badThirteen = new Movie(this, "badThirteen.mp4");
  badFourteen = new Movie(this, "badFourteen.mp4");
  badFifteen = new Movie(this, "badFifteen.mp4");
  badSixteen = new Movie(this, "badixteen.mp4");
  badSeventeen = new Movie(this, "badSeventeen.mp4");
  badEighteen = new Movie(this, "badEighteen.mp4");
  badNineteen = new Movie(this, "badNineteen.mp4");
  badTwenty = new Movie(this, "badTwenty.mp4");
  badTwentyone = new Movie(this, "badTwentyone.mp4");
  badTwentytwo = new Movie(this, "badTwentytwo.mp4");
  badTwentythree = new Movie(this, "badTwentythree.mp4");
  badTwentyfour = new Movie(this, "badTwentyfour.mp4");
  badTwentyfive = new Movie(this, "badTwentyfive.mp4");
 
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
}
 
void draw() {
  // set the background color with the color values:
  background(0);
}
 
void serialEvent(Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');
 
  if (inString != null) {
  // trim off any whitespace:
  inString = trim(inString);
  // split the string on the commas and convert the
  // resulting substrings into an integer array:
  float[] colors = float(split(inString, ","));
  // if the array has at least three elements, you know
  // you got the whole thing.  Put the numbers in the
  // color variables:
  if (colors.length >=3) {
  // map them to the range 0-255:
  redValue = map(colors[0], 0, 1023, 0, 255);
  greenValue = map(colors[1], 0, 1023, 0, 255);
  }
  }
  }
 

I'm working off a color mixing arduino -> processing sketch so thats why the bottom is redvalues and greenvalues, i have changed these to clubvalues and cup values. whenever the fsr registers a value over 1, that should start or stop the timer. i'm kind of using it as a switch here and not an actual analog sensor. i tried changing the values from 0/1023 to 0/1 in processing, but you need to be pressing it at the hardness threshold to register a 1, so i just left it. thanks guys.
Pages: [1]