| Arduino Forum ::  Members :: hlawan
 Show Posts Pages: [1]
 1 Using Arduino / Programming Questions / Re: [Solved] Adjusting shift register outputs to the signal of light barriers on: February 13, 2013, 05:15:41 pm I knew this question would come up Well, I'm building a table...a beer-pong table. Beer pong is a drinking game (throw ping pong balls at cups filled with beer) famous in the USA ( http://en.wikipedia.org/wiki/Beer_pong ) and somehow that crossed my way and i decided to build a beer-pong table. I made a 3d model (see attachment) and somehow my plans for the table became more and more complex. At some point I decided that the table needs some kind of intelligence and that's how I got in touch with micro controllers and programming...well and during the project I noticed that I really like spending my time learning the basics of programming...the white surfaces in the drawing is milky acrylic glass and all the stripes are LED stripes under the acrylic glass.The holes are of course the holes I was taking about in which the cups are placed and the LEDs we are taking about will be placed under the milky acrylic glass. The small red pyramids will show which cups are still in the game on the other side.The blue holes are automatic ping pong ball washers. (If you search for "beer pong table" on youtube you can see how they work)
 2 Using Arduino / Programming Questions / Re: [Solved] Adjusting shift register outputs to the signal of light barriers on: February 13, 2013, 02:23:26 pm You are right the code is getting more difficult to understand but I think since we kind of developed it "together" I truly understood every step (but the map() thing )In case I forget something I'll always be able to look it up in this thread I included your clearTwoBits function. It will come handy as soon as I build my 20 hole final version.Works perfectly.Code://defining pinsint S0 = 8;int S1 = 9;int S2 = 10;int SensorPin = A0;int dataPin = 2;        int latchPin = 3;int clockPin = 4;//defining variablesint sCup[6] ;byte LEDpattern[] = {B00000000, B00000000};byte maskCup[] = {B00000011, B00001100, B00110000, B11000000, B00000011, B00001100};int SOvalue[] = {0,1,0,1,0,1};int S1value[] = {0,0,1,1,0,0};int S2value[] = {0,0,0,0,1,1};void setup(){  //Configure each IO Pin  pinMode(S0, OUTPUT);        pinMode(S1, OUTPUT);  pinMode(S2, OUTPUT);    pinMode(SensorPin, INPUT);  pinMode(dataPin, OUTPUT);         pinMode(latchPin, OUTPUT);  pinMode(clockPin, OUTPUT);}void loop() {  //read out sensor values and store them in sCup[]  for (int i=0 ; i<6 ; i++)  {    digitalWrite (S0, SOvalue[i]);    digitalWrite (S1, S1value[i]);    digitalWrite (S2, S2value[i]);    sCup[i] = analogRead (SensorPin);  }  //adjust LED pattern to SensorValues and shift out data  for (int i = 0 ; i < 6 ; i++)  {    int value = (sCup[i] < 500) ? LOW : HIGH;      int patternValue = (i < 4) ? LOW : HIGH;    switch (value)     {    case  0:      LEDpattern[patternValue] = (LEDpattern[patternValue] | maskCup[i]);      break;    case  1:      switch (i)       {      case 0:        clearTwoBits(0, 0, 1);        break;      case 1:        clearTwoBits(0, 2, 3);        break;      case 2:        clearTwoBits(0, 4, 5);        break;      case 3:        clearTwoBits(0, 6, 7);        break;      case 4:        clearTwoBits(1, 0, 1);        break;      case 5:        clearTwoBits(1, 2, 3);        break;      }     }    digitalWrite(latchPin, LOW);                shiftOut(dataPin, clockPin, MSBFIRST, LEDpattern[1]);             shiftOut(dataPin, clockPin, MSBFIRST, LEDpattern[0]);    digitalWrite(latchPin, HIGH);   }}//defining Function to clear two bitsvoid clearTwoBits(int patternNumber, int firstBit, int secondBit)  {    bitClear(LEDpattern[patternNumber] , firstBit);    bitClear(LEDpattern[patternNumber] , secondBit);    }
 3 Using Arduino / Programming Questions / Re: [Solved] Adjusting shift register outputs to the signal of light barriers on: February 13, 2013, 01:52:52 pm QuoteThese and the following onesCode:  //read out sensor cup 0  digitalWrite (S0, LOW);  digitalWrite (S1, LOW);  digitalWrite (S2, LOW);  sCup[0] = analogRead (SensorPin);  //read out sensor cup 1  digitalWrite (S0, HIGH);  digitalWrite (S1, LOW);  digitalWrite (S2, LOW);  sCup[1] = analogRead (SensorPin);look like another candidate for a for loop based on the cup number.  Each of them writes a pattern to the same LEDs and reads the corresponding sensor value.  If you put the HIGH/LOW values to be written in an array with the cup number as its row index and the 3 HIGH/LOW values as columns then you could get the values to be written to S0, S1 and S2 from the array row for the cup number and the sCup[] index number will be the for loop variable.One reason for suggesting changing the cup numbers in the comments was that, as you know, the array index starts at zero not one.  With the comments changed there is less chance of confusion I think.(I think), I did that. I modified my post right after posting it, maybe you still saw the old version?