potentiometer and seven segment display


hello in part of program turn potentiometer , segment on display changes different values of it......i have 2 versions of same program, last 1 doesnt't work....someone can kindly see can change in first??

first version works not elegant

#define latch 7
#define clock 8
#define data 4
#define pot2 1
#define buttonpin 11
#define buzzer 3
#define pitch 1000
 #include "pitches.h"
int prec_stato=0;
unsigned long elapsed;
           
int fractional;
unsigned long start;
unsigned long finished;

int melody[] = {
  note_c4, note_g3,note_g3, note_a3, note_g3,0, note_b3, note_c4};

int notedurations[] = {
  4, 8, 8, 4,4,4,4,4 };

int buttonpushcounter;
const byte numeral[10] = {
//abcdefg /dp
b11000000, // 0//okokok
b11111001, // 1//okokok
b10100100, // 2//okokok
b10110000, // 3//okokok
b10011001, // 4//okokok
b10010010, // 5//okokok
b10000010, // 6//okokok
b11111000, // 7//okokok
b10000000, // 8//okokok
b10011000, // 9//okokok
};

int  buttonstate;

void displayresult()
{
float h, m, s, ms;
unsigned long over;
elapsed = finished - start;

h= int (elapsed/3600000);
over=elapsed%3600000;
m= int (over/60000);
over=over%60000;
s=int(over/1000);
ms=over%1000;

serial.print("raw elapsed time: ");
serial.println(elapsed);
serial.print("elapsed time: ");
serial.print(h,0);
serial.print("h ");
serial.print(m,0);
serial.print("m ");
serial.print(s,0);
serial.print("s ");
serial.print(ms,0);
serial.print("ms ");
serial.println();

}

void displaydigit()
{
 
int y = analogread(pot2);

if (y>0 && y<100)
 {
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[1]);
 digitalwrite(latch,high);
 start = millis();
}

else if (y>100 && y<200)
{
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[2]);
 digitalwrite(latch,high);
 start = millis();
 }

 
else if (y>200 && y<300)
{
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[3]);
 digitalwrite(latch,high);
 start = millis();
}

else if (y>300 && y<400)
{
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[4]);
 digitalwrite(latch,high);
 start = millis();
}
 
else if (y>400 && y<500)
{
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[5]);
 digitalwrite(latch,high);
 start = millis();
}

else if (y>500 && y<600)
{
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[6]);
 digitalwrite(latch,high);
 start = millis();
}
 
else if (y>600 && y<700)
{
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[7]);
 digitalwrite(latch,high);
 start = millis();
  }
else if (y>700 && y<800)
{
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[8]);
 digitalwrite(latch,high);
 start = millis();
 }

else if (y>800 && y<1000)
{
 digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[9]);
 digitalwrite(latch,high);
 start = millis();
 }
 
}




void setup()
{
  serial.begin(9600);
 pinmode(latch, output);
 pinmode(clock, output);
 pinmode(data,output);
 pinmode(pot2, input);
 pinmode(buttonpin, input);
//digitalwrite(buttonpin, high); 
digitalwrite(buttonpin, low);
 pinmode(buzzer,output);
}



void loop()
{
displaydigit();

   int buttonstate =  digitalread(buttonpin);
     if (buttonstate!=prec_stato)
     {
     if (!buttonstate)
     {
     tone(buzzer,pitch);
     serial.print("pressed");
     finished = millis();
     delay(2000);
     displayresult();
     delay(2000);
     }
       
      else
     
        {
       serial.print("not pressed");
       notone(3);
        }
     
     prec_stato=buttonstate;
   }

}


second version doesn' t work

#define latch 7
#define clock 8
#define data 4
#define pot2 1
#define buttonpin 11
#define buzzer 3
#define pitch 1000
 #include "pitches.h"
int prec_stato=0;
unsigned long elapsed;
int i=0; 
int j=0;
int fractional;
unsigned long start;
unsigned long finished;
char range[10];

int buttonpushcounter;
const byte numeral[10] = {
//abcdefg /dp
b11000000, // 0//okokok
b11111001, // 1//okokok
b10100100, // 2//okokok
b10110000, // 3//okokok
b10011001, // 4//okokok
b10010010, // 5//okokok
b10000010, // 6//okokok
b11111000, // 7//okokok
b10000000, // 8//okokok
b10011000, // 9//okokok
};

int  buttonstate;

void displayresult()
{
float h, m, s, ms;
unsigned long over;
elapsed = finished - start;

h= int (elapsed/3600000);
over=elapsed%3600000;
m= int (over/60000);
over=over%60000;
s=int(over/1000);
ms=over%1000;

serial.print("raw elapsed time: ");
serial.println(elapsed);
serial.print("elapsed time: ");
serial.print(h,0);
serial.print("h ");
serial.print(m,0);
serial.print("m ");
serial.print(s,0);
serial.print("s ");
serial.print(ms,0);
serial.print("ms ");
serial.println();

}

void displaydigit()
{
 
int y = analogread(pot2);

range[10]=1023/10;



  (j=0;j<10; j++)
  {
  for(i=0;i<10;i++)
{
  while (y==range)
  {
  digitalwrite(latch,low);
 shiftout(data,clock,msbfirst,numeral[j]);
 digitalwrite(latch,high);
 start = millis();

}
}
  }

}


void setup()
{
  serial.begin(9600);
 pinmode(latch, output);
 pinmode(clock, output);
 pinmode(data,output);
 pinmode(pot2, input);
 pinmode(buttonpin, input);
//digitalwrite(buttonpin, high); 
digitalwrite(buttonpin, low);
 pinmode(buzzer,output);
}



void loop()
{
displaydigit();

   int buttonstate =  digitalread(buttonpin);
     if (buttonstate!=prec_stato)
     {
     if (!buttonstate)
     {
     tone(buzzer,pitch);
     serial.print("pressed");
     finished = millis();
     delay(2000);
     displayresult();
     delay(2000);
     }
       
      else
     
        {
       serial.print("not pressed");
       notone(3);
        }
     
     prec_stato=buttonstate;
   }

}



//start = millis();

/* while (digitalread(buttonpin)==low)
{
  //wait until press button
  ;
  tone(buzzer,pitch);
   serial.print("pressed");
  }
 
/* if(digitalread(buttonpin)==low)
  {
   tone(buzzer,pitch);
   serial.print("pressed");
  } */
 // finished = millis();
 

//notone(3);

many

when write doesn't work, doing isn't correct?


Arduino Forum > Using Arduino > Programming Questions > potentiometer and seven segment display


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code