Need help fixing code please

Noob here, can anyone help me?

"‘timer_count’ was not declared in this scope"

Error is in void setup on the "MsTimer2::set" line

If i remove this, the code compiles
` // PWM specification setting
TCCR1A = 0b00100001;
TCCR1B = 0b00010001;//分周比1

// PWM setting
OCR1A = (unsigned int)(8000000 / frq );

//for development
// Serial.begin(9600);
}`

FULL CODE

//Clock M_D module
#include <MsTimer2.h>
#include <avr/io.h>

//---------basic waveform make--------------------
unsigned int frq = 60000; //frequency
float duty = 0.5;//pin10
int wave = 1000;//output wave form , fand + harm
const static word fand[180] PROGMEM = {
 0,  17, 34, 52, 69, 86, 103,  120,  137,  154,  171,  187,  203,  219,  234,  250,  264,  279,  293,  307,  321,  334,  347,  359,  371,  383,  394,  404,  414,  424,  433,  441,  449,  456,  463,  469,  475,  480,  485,  489,  492,  495,  497,  498,  499,  500,  499,  498,  497,  495,  492,  489,  485,  480,  475,  469,  463,  456,  449,  441,  433,  424,  414,  404,  394,  383,  371,  359,  347,  334,  321,  307,  293,  279,  264,  250,  234,  219,  203,  187,  171,  154,  137,  120,  103,  86, 69, 52, 34, 17, 0,  -18,  -35,  -53,  -70,  -87,  -104, -121, -138, -155, -172, -188, -204, -220, -235, -250, -265, -280, -294, -308, -322, -335, -348, -360, -372, -384, -395, -405, -415, -425, -434, -442, -450, -457, -464, -470, -476, -481, -486, -490, -493, -496, -498, -499, -500, -500, -500, -499, -498, -496, -493, -490, -486, -481, -476, -470, -464, -457, -450, -442, -434, -425, -415, -405, -395, -384, -372, -360, -348, -335, -322, -308, -294, -280, -265, -250, -235, -220, -204, -188, -172, -155, -138, -121, -104, -87,  -70,  -53,  -35,  -18
};
const static word harm[180] PROGMEM = {
 0,  416,  365,  321,  334,  307,  279,  279,  254,  232,  227,  203,  185,  178,  155,  140,  131,  110,  97, 88, 68, 57, 48, 30, 21, 11, -4, -11,  -21,  -34,  -40,  -48,  -60,  -63,  -71,  -80,  -82,  -88,  -95,  -95,  -101, -104, -103, -107, -109, -106, -109, -107, -103, -104, -101, -95,  -95,  -88,  -82,  -80,  -71,  -63,  -60,  -48,  -40,  -34,  -21,  -11,  -4, 11, 21, 30, 48, 57, 68, 88, 97, 110,  131,  140,  155,  178,  185,  203,  227,  232,  254,  279,  279,  307,  334,  321,  365,  416,  0,  -417, -366, -322, -335, -308, -280, -280, -255, -233, -228, -204, -186, -179, -156, -141, -132, -111, -98,  -89,  -69,  -58,  -49,  -31,  -22,  -12,  3,  10, 20, 33, 39, 47, 59, 62, 70, 79, 81, 87, 94, 94, 100,  103,  102,  106,  108,  105,  108,  106,  102,  103,  100,  94, 94, 87, 81, 79, 70, 62, 59, 47, 39, 33, 20, 10, 3,  -12,  -22,  -31,  -49,  -58,  -69,  -89,  -98,  -111, -132, -141, -156, -179, -186, -204, -228, -233, -255, -280, -280, -308, -335, -322, -366, -417
};

//-------------trig------------
bool trig = 0;//
bool old_trig = 0;//

//-----------control wave color------------
int h = 0; //table finish count
int i = 0; //waveform
byte j = 1; //decay frequency
float k = 1; //decay amp

int knob_tone = 512;
int knob_harm = 512;
int knob_attack = 512;
int knob_decay = 512;
int CV_harm = 512;


unsigned long ext_count = 400;//タイマーカウント用
unsigned long old_ext_pulse = 0;
unsigned long old_int_pulse = 0;
unsigned long ext_period = 0;//周期
unsigned long ext_count_result = 0;//タイマーのカウント結果
unsigned long old_ext_count_result = 0;//タイマーのカウント結果
byte ext_pulse = 0;//外部クロック あれば1、なければ0
byte int_pulse = 0;//内部クロック
byte ext_injudge = 1;//外部入力有無判定。あれば1,なければ0。タイマーカウントが規定値超えると判定切り替え
byte old_ext_injudge = 2;

int AD_rate = 512;//rateノブの入力
int rate = 1000;//内部クロック動作時に使用

int AD_MD = 512;//MDノブの入力値
int out_width_ch1 = 10;//アウトプットのパルス幅。
int out_width_ch2 = 10;//アウトプットのパルス幅。
int old_AD_MD = 512;//SW切り替え時のRATE値誤読対策
int MD_ch1 = 5;//マルチプル、ディバイダー判定ch1
int MD_ch2 = 5;//マルチプル、ディバイダー判定ch2
int M_period_ch1 = 0;//マルチプルの時、出力クロックの周期。マルチプルでなければ0とする。
int M_period_ch2 = 0;//マルチプルの時、出力クロックの周期。マルチプルでなければ0とする。
int M_count_ch1 = 1;//マルチプルの時、パルスごとにカウントし、設定値に達すると0に戻る
int M_count_ch2 = 1;//マルチプルの時、パルスごとにカウントし、設定値に達すると0に戻る
int D_count_ch1 = 1;//外部パルスが入るとカウントを位置上げる
int D_count_ch2 = 1;//外部パルスが入るとカウントを位置上げる
int D_full_ch1 = 1;//カウントの上限値
int D_full_ch2 = 1;//カウントの上限値
byte CH1out = 0;//0でLOW出力、1でHIGH出力
byte CH2out = 0;//0でLOW出力、1でHIGH出力
byte M_done_ch1 = 0; //マルチプルの出力確認用。ないと、1クロックで複数パルスでてしまう
byte M_done_ch2 = 0; //マルチプルの出力確認用。ないと、1クロックで複数パルスでてしまう


//---mode切り替え-------------
byte mode_sw = 1;
byte mode = 1;//1=CH1,2=CH2
byte old_mode = 0;//SW切り替え時のRATE値誤読対策
int old_MD_ch1 = 0;//スイッチ切り替え時にディバイダーのクロックが狂うバグ対策
int old_MD_ch2 = 0;//スイッチ切り替え時にディバイダーのクロックが狂うバグ対策

void setup() {
 pinMode(7, OUTPUT); //CH1out
 pinMode(8, OUTPUT); //CH2out
 pinMode(13, OUTPUT); //internal_clock_out
 pinMode(11, INPUT); //ext_clock_in
  pinMode(10, OUTPUT);//sound output
 pinMode(12, OUTPUT);//LED
 Serial.begin(9600);
 

 MsTimer2::set(1, timer_count); // 1ms毎にタイマーカウント
 MsTimer2::start();//外部入力Highになったら、次のHighまでカウント
}

 // PWM specification setting
 TCCR1A = 0b00100001;
 TCCR1B = 0b00010001;//分周比1

 // PWM setting
 OCR1A = (unsigned int)(8000000 / frq );

 //for development
 //  Serial.begin(9600);
}


void loop() {
 AD_MD = analogRead(3);
 AD_rate = 1023 - analogRead(4);
 rate = AD_rate * 2 + 100;

 old_ext_pulse = ext_pulse;
 old_int_pulse = int_pulse;
 ext_pulse = digitalRead(3);

 mode_sw = digitalRead(11);
 old_mode = mode;

 old_ext_injudge = ext_injudge;

 //-----------ディバイダー出力のカウントリセット------------
 if (D_count_ch1 >= D_full_ch1) {
   D_count_ch1 = 0;
 }
 if (D_count_ch2 >= D_full_ch2) {
   D_count_ch2 = 0;
 }

 //------------------------------------
  old_trig = trig;
 trig = digitalRead(11);

 digitalWrite(12, trig); //LED ON during trigger is high

 if (old_trig == 0 && trig == 1) {//trigger detect
   h = 0;
   i = 0;
   j = 0;
   k = 1;
 }

 

 

 //-----------SWの読み取り---------------

 old_MD_ch1 = MD_ch1;//スイッチ切り替え時にディバイダーのクロックが狂うバグ対策
 old_MD_ch2 = MD_ch2;//スイッチ切り替え時にディバイダーのクロックが狂うバグ対策

 if ( mode_sw == 1  ) {
   mode = 1;
 }
 else if (mode_sw == 0  ) {
   mode = 2;
 }

 if ( old_mode != mode ) {//スイッチ切り替え時にディバイダーのクロックが狂うバグ対策
   old_AD_MD = AD_MD;
 }

  i ++;
 if (i > 179) {

   knob_tone = analogRead(0) / 64;
   knob_harm = (1023 - analogRead(1) ) / 32;
   knob_decay = analogRead(3) / 16;
   knob_attack = analogRead(5) / 16;
   CV_harm = analogRead(2) / 32;

   knob_harm = knob_harm - CV_harm;

   if ( knob_harm >= 31) {
     knob_harm = 31;
   }

   

   //make decay
   h ++;
   i = 0;
   j = j + 5;//modulate wave frequency slower rate

   if (knob_decay <= 32) { //no body decay
     k = k * (98 - (32 - knob_decay)) / 100 - 10 / 100;
   }
   else if (knob_decay > 32) { //with body decay
     if (h < (16 - knob_tone) / 2) {
       k = 0.8 + h / 16 / 5;
     }
     else {
       k = k * (94 -  (knob_decay - 32)) / 100 - 10 / 100;
     }
   }
 }

 delayMicroseconds((knob_tone) * j);//modulate wave frequency slower

  //---------kick wave making------------------
 if (h == 0 && i < knob_attack  && knob_attack >= 5) { // make punch sound by noise
   wave = (pgm_read_word(&(fand[random(0, 179)]))) * 32 + (pgm_read_word(&(harm[i]))) * (32 - knob_harm);
 }

 else if (h <= 1 && i > 25 && i < 90) {
   wave = (pgm_read_word(&(fand[i]))) * (32 + knob_attack / 3) + (pgm_read_word(&(harm[i]))) * (32 - knob_harm);
 }

 else {
   wave = (pgm_read_word(&(fand[i]))) * 32 + (pgm_read_word(&(harm[i]))) * (32 - knob_harm);
 }

 wave = wave * k;
 wave = wave / 32 + 500;

 duty = (float)wave / 1000;

 

 

 //---------MDノブ判定-----------------------

 if ( mode == 1 && abs(old_AD_MD - AD_MD ) > 30) { //absはスイッチ切り替え時にディバイダーのクロックが狂うバグ対策
   old_AD_MD = 1200;//abs(old_AD_MD - AD_MD ) > 30が絶対に成立するため

   if ( AD_MD >= 0 && AD_MD < 20) {
     MD_ch1 = 9;//*16
   }

   else if ( AD_MD >= 20 && AD_MD < 90) {
     MD_ch1 = 8;//*8
   }

   else if ( AD_MD >= 90 && AD_MD < 240) {
     MD_ch1 = 7;//*4
   }

   else if ( AD_MD >= 240 && AD_MD < 400) {
     MD_ch1 = 6;//*2
   }

   else if ( AD_MD >= 400 && AD_MD < 550) {
     MD_ch1 = 5;//*1
   }

   else if ( AD_MD >= 550 && AD_MD < 700) {
     MD_ch1 = 4;//1/2
   }

   else if ( AD_MD >= 700 && AD_MD < 820) {
     MD_ch1 = 3;//1/3
   }

   else if ( AD_MD >= 820 && AD_MD < 960) {
     MD_ch1 = 2;//1/4
   }

   else if ( AD_MD >= 960 && AD_MD < 1024) {
     MD_ch1 = 1;//1/8
   }
 }

 else if ( mode == 2 && abs(old_AD_MD - AD_MD ) > 30) {  //absはスイッチ切り替え時にディバイダーのクロックが狂うバグ対策
   old_AD_MD = 1200;//abs(old_AD_MD - AD_MD ) > 30が絶対に成立するため

   if ( AD_MD >= 0 && AD_MD < 20) {
     MD_ch2 = 9;//*16
   }

   else if ( AD_MD >= 20 && AD_MD < 90) {
     MD_ch2 = 8;//*8
   }

   else if ( AD_MD >= 90 && AD_MD < 240) {
     MD_ch2 = 7;//*4
   }

   else if ( AD_MD >= 240 && AD_MD < 400) {
     MD_ch2 = 6;//*2
   }

   else if ( AD_MD >= 400 && AD_MD < 550) {
     MD_ch2 = 5;//*1
   }

   else if ( AD_MD >= 550 && AD_MD < 700) {
     MD_ch2 = 4;//1/2
   }

   else if ( AD_MD >= 700 && AD_MD < 820) {
     MD_ch2 = 3;//1/3
   }

   else if ( AD_MD >= 820 && AD_MD < 960) {
     MD_ch2 = 2;//1/4
   }

   else if ( AD_MD >= 960 && AD_MD < 1024) {
     MD_ch2 = 1;//1/8
   }
 }


 switch (MD_ch1) {
   case 1:
     out_width_ch1 = ext_period / 2 / 8;
     M_period_ch1 = ext_period / 8;
     break;

   case 2:
     out_width_ch1 = ext_period / 2 / 4;
     M_period_ch1 = ext_period / 4;
     break;

   case 3:
     out_width_ch1 = ext_period / 2 / 3;
     M_period_ch1 = ext_period / 3;
     break;

   case 4:
     out_width_ch1 = ext_period / 2 / 2;
     M_period_ch1 = ext_period / 2;
     break;

   case 5:
     out_width_ch1 = ext_period / 2 ;
     M_period_ch1 = 0;
     D_full_ch1 = 1;
     break;

   case 6:
     out_width_ch1 = ext_period / 2;
     M_period_ch1 = 0;
     D_full_ch1 = 2;
     break;

   case 7:
     out_width_ch1 = ext_period / 2;
     M_period_ch1 = 0;
     D_full_ch1 = 4;
     break;

   case 8:
     out_width_ch1 = ext_period / 2;
     M_period_ch1 = 0;
     D_full_ch1 = 8;
     break;

   case 9:
     out_width_ch1 = ext_period / 2;
     M_period_ch1 = 0;
     D_full_ch1 = 16;
     break;
 }


 switch (MD_ch2) {
   case 1:
     out_width_ch2 = ext_period / 2 / 8;
     M_period_ch2 = ext_period / 8;
     break;

   case 2:
     out_width_ch2 = ext_period / 2 / 4;
     M_period_ch2 = ext_period / 4;
     break;

   case 3:
     out_width_ch2 = ext_period / 2 / 3;
     M_period_ch2 = ext_period / 3;
     break;

   case 4:
     out_width_ch2 = ext_period / 2 / 2;
     M_period_ch2 = ext_period / 2;
     break;

   case 5:
     out_width_ch2 = ext_period / 2 ;
     M_period_ch2 = 0;
     D_full_ch2 = 1;
     break;

   case 6:
     out_width_ch2 = ext_period / 2 ;
     M_period_ch2 = 0;
     D_full_ch2 = 2;
     break;

   case 7:
     out_width_ch2 = ext_period / 2 ;
     M_period_ch2 = 0;
     D_full_ch2 = 4;
     break;

   case 8:
     out_width_ch2 = ext_period / 2 ;
     M_period_ch2 = 0;
     D_full_ch2 = 8;
     break;

   case 9:
     out_width_ch2 = ext_period / 2 ;
     M_period_ch2 = 0;
     D_full_ch2 = 16;
     break;
 }

 if ( MD_ch1 != old_MD_ch1 || MD_ch2 != old_MD_ch2 ) { //スイッチ切り替え時にディバイダーのクロックが狂うバグ対策
   D_count_ch1 = 0;
   D_count_ch2 = 0;
 }

 //------------外部入力有無判定-------------------------------
 if ( ext_count > 4000 ) { //4s以上カウントが無ければ、外部入力無し判定
   ext_injudge = 0;
 }
 else if ( ext_count < 4000 && ext_pulse == 1 ) {
   ext_injudge = 1;
 }

 if ( old_ext_injudge == 1 && ext_injudge == 0 ) { //外部入力が有→無のとき
   ext_count = 0;
 }


 //---------クロック設定------------------------
 if ( ext_injudge != 0 ) { //外部クロックを使用
   if (ext_pulse == 1 && old_ext_pulse == 0) {
     old_ext_count_result = ext_count_result;//2回の平均取る用
     ext_count_result = ext_count;
     //            ext_count = 0;
     ext_period = (old_ext_count_result + ext_count_result) / 2;//外部入力周期。ばらつき低減のため2回の平均値
     //      MsTimer2::start();//外部入力Highになったら、次のHighまでカウント
   }
 }
 else if ( ext_injudge == 0) { //内部クロックを使用
   ext_period = rate;
   if ( ext_count < 5 || ext_count >= ext_period) {
     int_pulse = 1;
   }
   else if (ext_count >= 5 ) {
     int_pulse = 0;
   }

 }
 //--------------INTERNAL CLOCK出力(外部入力無い場合のみ)-----------

 if ( int_pulse == 1 ) {
   digitalWrite(13, HIGH);
 }
 else if ( ext_count >= ext_period / 2  ) {
   digitalWrite(13, LOW);
 }

 //-----------------OUT1出力------------------
 if (ext_pulse == 1 && old_ext_pulse == 0) {//外部クロック用
   D_count_ch1 ++;
   ext_count = 0;
   M_count_ch1 = 0;
   M_done_ch1 = 0;
   if ( MD_ch1 <= 4 ) {
     digitalWrite(7, HIGH);
     CH1out = 1;
   }
 }

 if (int_pulse == 1 && old_int_pulse == 0) {//内部クロック用
   D_count_ch1 ++;
   ext_count = 0;
   M_count_ch1 = 0;
   M_done_ch1 = 0;
   if ( MD_ch1 <= 4 ) {
     digitalWrite(7, HIGH);
     CH1out = 1;
   }
 }

 if ( MD_ch1 < 5 ) {
   if ( ext_count  >= M_period_ch1  * M_count_ch1  && CH1out == 0) {
     CH1out = 1;
     digitalWrite(7, HIGH);
   }
   if ( ext_count >= M_period_ch1  * M_count_ch1 + out_width_ch1  && CH1out == 1 ) {
     digitalWrite(7, LOW);
     M_count_ch1 ++;
     CH1out = 0;
   }
 }

 else if ( MD_ch1 == 5 ) {
   if (D_count_ch1 == 1 && M_done_ch1 == 0) {
     CH1out = 1;
     M_done_ch1 = 1;
     digitalWrite(7, HIGH);
   }
   if ( ext_count >=  out_width_ch1   ) {
     digitalWrite(7, LOW);
     CH1out = 0;
   }
 }

 else if ( MD_ch1 > 5 ) {
   if (D_count_ch1 == 1 && M_done_ch1 == 0) {
     CH1out = 1;
     digitalWrite(7, HIGH);
     M_done_ch1 = 1;
   }
   if ( ext_count >=  out_width_ch1   ) {
     digitalWrite(7, LOW);
     CH1out = 0;
   }
 }


 //-----------------OUT2出力------------------
 if (ext_pulse == 1 && old_ext_pulse == 0) {
   D_count_ch2 ++;
   M_count_ch2 = 0;
   M_done_ch2 = 0;
   if ( MD_ch2 <= 4 ) {
     digitalWrite(8, HIGH);
     CH2out = 1;
   }
 }

 if (int_pulse == 1 && old_int_pulse == 0) {//内部クロック用
   D_count_ch2 ++;
   M_count_ch2 = 0;
   M_done_ch2 = 0;
   if ( MD_ch2 <= 4 ) {
     digitalWrite(8, HIGH);
     CH2out = 1;
   }
 }

 if ( MD_ch2 < 5 ) {
   if ( ext_count  >= M_period_ch2  * M_count_ch2  && CH2out == 0) {
     CH2out = 1;
     digitalWrite(8, HIGH);
   }
   if ( ext_count >= M_period_ch2  * M_count_ch2 + out_width_ch2  && CH2out == 1 ) {
     digitalWrite(8, LOW);
     M_count_ch2 ++;
     CH2out = 0;
   }
 }

 else if ( MD_ch2 == 5 ) {
   if (D_count_ch2 == 1 && M_done_ch2 == 0) {
     CH2out = 1;
     M_done_ch2 = 1;
     digitalWrite(8, HIGH);
   }
   if ( ext_count >=  out_width_ch2   ) {
     digitalWrite(8, LOW);
     CH2out = 0;
   }
 }

 else if ( MD_ch2 > 5 ) {
   if (D_count_ch2 == 1 && M_done_ch2 == 0) {
     CH2out = 1;
     M_done_ch2 = 1;
     digitalWrite(8, HIGH);
   }
   if ( ext_count >=  out_width_ch2   ) {
     digitalWrite(8, LOW);
     CH2out = 0;
   }
 }


 //開発用

 Serial.print(ext_count);
 Serial.print(",");
 Serial.print(CH1out * 500);
 Serial.print(",");
 Serial.print(D_count_ch1 * 80);
 Serial.println("");

}

//タイマーカウント。1ms毎にカウントを増やす
void timer_count() {
 ext_count ++;
}

Is that the only error message?

where is the '{' here?

}

// PWM specification setting
TCCR1A = 0b00100001;
TCCR1B = 0b00010001;//分周比1

// PWM setting
OCR1A = (unsigned int)(8000000 / frq );

//for development
//  Serial.begin(9600);
}

yeah, that i know of

oops, now it says
"expected unqualified-id before '{' token"

i tried combining 2 working codes together

I'm sorry, I find that hard to believe.

i could be wrong, again im a noob

Combining, or cut and pasting? Because what you have looks like a cut and paste error. But most attempts to merge code without understanding it, don't succeed.

In general combining 2 sketches require knowledge of how each sketch works and often involves restructuring to avoid hardware, timing, and/or resource conflicts.

rodger that, i just cut and paste. i have no clue what im doing haha. luckily it works

Now.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.