Hello out there... i been working on this program that i found in YouTube. that make the Arduino in to a oscilloscope. the program works great.. but i want to remove the Swicth that are use to set some value that i want to make static. now i have tryed to do this for 3 weeks now and im not geting anywhere.. if anyone can help me out. that would be Great and thank you..
Here is the orginal code..
#include <ks0108.h>
#include <Arial14.h> // font definitions
#define txtLINE0 0
#define txtLINE1 16
#define txtLINE2 30
#define txtLINE3 46
#define RATE_MIN 0
#define RATE_MAX 13
#define RANGE_MIN 0
#define RANGE_MAX 4
const int LCD_WIDTH = 128;
const int LCD_HEIGHT = 64;
const int SAMPLES = 100;
const int ad_sw = 3; // Analog 3 pin for switches
const int ad_ch0 = 4; // Analog 4 pin for channel 0
const int ad_ch1 = 5; // Analog 5 pin for channel 1
const unsigned long VREF[] = {49, 98, 244, 488, 976}; // reference voltage 5.0V -> 50 : 1V/div range (100mV/dot)
// -> 100 : 0.5V/div
// -> 250 : 0.2V/div
// -> 500 : 100mV/div
// -> 1000 : 50mV/div
const int MILLIVOL_per_dot[] = {100, 50, 20, 10, 5}; // mV/dot
const int MODE_ON = 0;
const int MODE_INV = 1;
const int MODE_OFF = 2;
const char *Modes[] = {"ON", "INV", "OFF"};
const int TRIG_AUTO = 0;
const int TRIG_NORM = 1;
const int TRIG_SCAN = 2;
const int TRIG_ONE = 3;
const char *TRIG_Modes[] = {"Auto", "Norm", "Scan", "One"};
const int TRIG_E_UP = 0;
const int TRIG_E_DN = 1;
const char *Rates[] = {"F1-1", "F1-2 ", "F2 ", "5ms", "10ms", "20ms", "50ms", "0.1s", "0.2s", "0.5s", "1s", "2s", "5s", "10s"};
const char *Ranges[] = {" 1V ", "0.5V", "0.2V", "0.1V", "50mV"};
byte range0 = RANGE_MIN;
byte range1 = RANGE_MIN;
byte ch0_mode = 0, ch1_mode = 0, rate = 5;
byte trig_mode = TRIG_AUTO, trig_lv = 30, trig_edge = TRIG_E_UP, trig_ch = 0;
byte Start = 1, menu = 0;
byte data[4][SAMPLES]; // keep twice of the number of channels to make it a double buffer
byte sample=0; // index for double buffer
short ch0_off = 0, ch1_off = 0;
unsigned long startMillis;
void setup(){
GLCD.Init(NON_INVERTED); // initialise the library, non inverted writes pixels onto a clear screen
GLCD.SelectFont(Arial_14); // you can also make your own fonts, see playground for details
Serial.begin(9600);
GLCD.ClearScreen();
DrawGrid();
DrawText();
}
void CheckSW() {
static unsigned short oain[2];
static unsigned long Millis = 0, oMillis = 0;
unsigned long ms;
unsigned short ain = analogRead(ad_sw);
ms = millis();
if ((ms - Millis)<5)
return;
Millis = ms;
if (!(abs(oain[0] - oain[1])>10 && abs(oain[1] - ain)<2)) {
oain[0] = oain[1];
oain[1] = ain;
return;
}
oain[0] = oain[1];
oain[1] = ain;
if (ain > 950 || (Millis - oMillis)<200)
return;
oMillis = Millis;
// Serial.println(ain);
int sw;
for (sw = 0; sw < 10; sw ++) {
const int sw_lv[] = {889, 800, 700, 611, 514, 419, 338, 231, 132, 70};
if (ain > sw_lv[sw])
break;
}
// Serial.println(sw);
switch (menu) {
case 0:
default:
menu0_sw(sw);
break;
case 1:
menu1_sw(sw);
break;
case 2:
menu2_sw(sw);
break;
}
DrawText();
}
void menu0_sw(int sw) {
switch (sw) {
case 0:
// START/HOLD
if (Start)
Start = 0;
else
Start = 1;
break;
case 1:
// CH0 RANGE -
if (range0 < RANGE_MAX)
range0 ++;
break;
case 2:
// CH1 RANGE -
if (range1 < RANGE_MAX)
range1 ++;
break;
case 3:
// RATE FAST
if (rate > 0)
rate --;
break;
case 4:
// TRIG MODE
if (trig_mode < TRIG_ONE)
trig_mode ++;
else
trig_mode = 0;
break;
case 5:
// SEND
SendData();
break;
case 6:
// TRIG MODE
if (trig_mode > 0)
trig_mode --;
else
trig_mode = TRIG_ONE;
break;
case 7:
// RATE SLOW
if (rate < RATE_MAX)
rate ++;
break;
case 8:
// CH1 RANGE +
if (range1 > 0)
range1 --;
break;
case 9:
// CH0 RANGE +
if (range0 > 0)
range0 --;
break;
case 10:
default:
// MENU SW
menu ++;
break;
}
}
void menu1_sw(int sw) {
switch (sw) {
case 0:
// START/HOLD
if (Start)
Start = 0;
else
Start = 1;
break;
case 1:
// CH0 offset +
if (ch0_off < 1023)
ch0_off += 1024/VREF[range0];
break;
case 2:
// CH1 offset +
if (ch1_off < 1023)
ch1_off += 1024/VREF[range1];
break;
case 3:
// trigger level +
if (trig_lv < 60)
trig_lv ++;
break;
case 4:
case 6:
// TRIG EDGE
if (trig_edge == TRIG_E_UP)
trig_edge = TRIG_E_DN;
else
trig_edge = TRIG_E_UP;
break;
case 5:
// SEND
SendData();
break;
case 7:
// trigger level -
if (trig_lv > 0)
trig_lv --;
break;
case 8:
// CH1 OFF -
if (ch1_off > -1023)
ch1_off -= 1024/VREF[range1];
break;
case 9:
// CH0 OFF -
if (ch0_off > -1023)
ch0_off -= 1024/VREF[range0];
break;
case 10:
default:
// MENU SW
menu ++;
break;
}
}
void menu2_sw(int sw) {
switch (sw) {
case 0:
// START/HOLD
if (Start)
Start = 0;
else
Start = 1;
break;
case 1:
if (ch0_mode < 2)
ch0_mode ++;
break;
case 2:
if (ch1_mode < 2)
ch1_mode ++;
break;
case 3:
case 7:
// TRIG channel
if (trig_ch == 0)
trig_ch = 1;
else
trig_ch = 0;
break;
case 5:
// SEND
SendData();
break;
case 8:
if (ch1_mode > 0)
ch1_mode --;
break;
case 9:
if (ch0_mode > 0)
ch0_mode --;
break;
case 10:
// MENU SW
menu = 0;
break;
case 4:
case 6:
default:
// none
break;
}
}
there more...
osl.pde (13.9 KB)