online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <stdio.h> #include<stdbool.h> int note[] = {261, 293, 329, 349, 392, 440, 494, 523}; // from note[0] to note[7] const int MAX = 8; int recorded[8]; // for saving melody int i; // for 'for loop' int m; bool startrecording = true; // change this to 'false' if you want to turn back to 'just play' mode float U_ADC0 = 5; // here, I start by pushing button PB1 // change this value to check the output. For sure, you will get this (voltage) value from your ADC conversion // so, this is for checking purposes only... void play(float U_ADC0){ // function for 'just play' if(U_ADC0 >= 4.80) { // ADC conversion (Voltage value) PB1 m = note[0]; // m = 261 printf("%d ", m); // I deleted everything else that I cannot use in these if statements for checking purposes. } // You can copy your code into these if statements if(U_ADC0 < 4.80 && U_ADC0 >= 4.70){ //PB2 m = note[1]; // m = 293 printf("%d ", m); } if(U_ADC0 < 4.72 && U_ADC0 >= 4.65){ //PB3 m = note[2]; // m = 329 printf("%d ", m); } if(U_ADC0 < 4.60 && U_ADC0 >= 4.50){ //PB4 m = note[3]; // m = 349 printf("%d ", m); } if(U_ADC0 < 4.20 && U_ADC0 >= 4.05){ //PB5 m = note[4]; // m = 392 printf("%d ", m); } if(U_ADC0 < 3.80 && U_ADC0 >= 3.70){ //PB6 m = note[5]; // m = 440 printf("%d ", m); } if(U_ADC0 < 3.55 && U_ADC0 >= 3.30){ //PB7 m = note[6]; // m = 494 printf("%d ", m); } if(U_ADC0 < 2.55 && U_ADC0 >= 2.45){ //PB8 m = note[7]; // m = 523 printf("%d ", m); } } void recordandplay() { play(U_ADC0); if(i<7) // i starts from 0 and can go up to 7, which is enough for us to check all the 8 slots (bits) in the array { switch(i) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: // check 'i' is what number (starts from 0) recorded[i] = m; // then take that number write the value in the corresponding place i++; // then go to the next bit and wait for another button to get pushed break; // go out of this switch and wait for the next one, but remember now i is equal to 1, so whatever value you give, it will be stored in the first bit of 'recorded' array } // switch end } // if end } // recordandplay function end int main() { int run_times; for(run_times=0; run_times < 2; run_times++) // let's say I am going to push 2 different buttons (we run 2 times) { // We start with 'U_ADC0 = 5' (go to the beginning of your code - global variables), // but in your case it will change depending on which button you press if(startrecording) // if you have pushed the 'startrecording' button, it is going to call the 'recordandplay' function { recordandplay(); // I pushed button PB0 first in this function since 'U_ADC0 = 5' U_ADC0 = 3.4; // now, I push button PB7 for the next run (2nd and also the last run) } else { play(U_ADC0); // otherwise, just play } } for(i=0; i<8; i++){ // let's see what's in each bit of 'recorded' array printf("\n bit %d holds the value: %d", i, recorded[i]); } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue