示例#1
0
文件: menu.cpp 项目: zengrz/ENPH253
void RefreshCurSelection()
{
	int readKnob = knob(6);
	if (abs(knobValue - readKnob) > 10)
	{
		if (readKnob < knobValue)
		{
			if (curSelection > 1) curSelection -= 1;
		}
		else
		{
			if (curSelection < 9) curSelection += 1; // poor condition, what if this level does not go all the way up to 9? sol: set 9 to be quit.
		}
		knobValue = readKnob;
	}
}
示例#2
0
void Refresh_303_Unit(int Unit, int gode)
{
    char tcp[40];

    if(userscreen == USER_SCREEN_TB303_EDIT)
    {
    
        if(gode == 0 ||
           gode == 1)
        {
            number303(tb303[Unit].patternlength[tb303[Unit].selectedpattern], 118, (Cur_Height - 44));
        }

        // Selected bassline
        if(gode == 0)
        {
            if(Unit)
            {
                Skincopy(577, (Cur_Height - 58), 138, 119, 3, 3);
                Skincopy(558, (Cur_Height - 58), 143, 119, 3, 3);
                Gui_Draw_Button_Box(668, (Cur_Height - 78), 64, 16, "Tune to 1", BUTTON_NORMAL | BUTTON_TEXT_CENTERED);
            }
            else
            {
                Skincopy(558, (Cur_Height - 58), 138, 119, 3, 3);
                Skincopy(577, (Cur_Height - 58), 143, 119, 3, 3);
                Gui_Draw_Button_Box(668, (Cur_Height - 78), 64, 16, "Tune to 2", BUTTON_NORMAL | BUTTON_TEXT_CENTERED);
            }

            // Make sure we display the right boundaries
            if(editsteps[Unit][tb303[Unit].selectedpattern] > tb303[Unit].patternlength[tb303[Unit].selectedpattern] - 1)
            {
                editsteps[Unit][tb303[Unit].selectedpattern] = tb303[Unit].patternlength[tb303[Unit].selectedpattern] - 1;
            }

            number303(editsteps[Unit][tb303[Unit].selectedpattern] + 1, 486, (Cur_Height - 114));
            // Displaying pattern selection leds
            // Bank [A-D]
            int tbank303 = tb303[Unit].selectedpattern / 8;
            tbank303 *= 15;
            // Restoring background
            Skincopy(86, (Cur_Height - 74), 6, 66, 59, 14);
            // Light the bank
            Skincopy(86 + tbank303, (Cur_Height - 74), 15 + tbank303, 117, 14, 14);
            // Displaying pattern selection leds
            // Pattern [1-8]
            int tpat303 = tb303[Unit].selectedpattern - (tb303[Unit].selectedpattern / 8) * 8;
            // Restoring background
            Skincopy(86, (Cur_Height - 116), 6, 24, 59, 30);
            // Light the bank
            if(tpat303 < 4)
            {
                Skincopy(86 + tpat303 * 15, (Cur_Height - 116), 75 + tpat303 * 15, 117, 14, 14);
            }
            else
            {
                tpat303 -= 4;
                Skincopy(86 + tpat303 * 15, (Cur_Height - 101), 75 + tpat303 * 15, 132, 14, 14);
            }
        }

        // Displaying waveform switch
        if(gode == 0 || gode == 2)
        {
            if(tb303[Unit].waveform) Skincopy(180, (Cur_Height - 128), 137, 135, 13, 8);
            else Skincopy(180, (Cur_Height - 128), 137, 125, 13, 8);
        }

        // Draw 303 Knobs
        if(gode == 0 || gode == 3) knob(229, (Cur_Height - 124), tb303[Unit].tune / 2);
        if(gode == 0 || gode == 4) knob(262, (Cur_Height - 124), tb303[Unit].cutoff / 2);
        if(gode == 0 || gode == 5) knob(295, (Cur_Height - 124), tb303[Unit].resonance / 2);
        if(gode == 0 || gode == 6) knob(328, (Cur_Height - 124), tb303[Unit].envmod / 2);
        if(gode == 0 || gode == 7) knob(361, (Cur_Height - 124), tb303[Unit].decay / 2);
        if(gode == 0 || gode == 8) knob(394, (Cur_Height - 124), tb303[Unit].accent / 2);

        // Restoring notes background
        if(gode == 0 || gode == 9)
        {
            // Restore it
            Skincopy(88 + 80, 66 + (Cur_Height - 140), 88, 66, 195, 40);

            // Light a note
            switch(tb303[Unit].tone[tb303[Unit].selectedpattern][editsteps[Unit][tb303[Unit].selectedpattern]])
            {
                case 0: Skincopy(88 + 80, 91 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 1: Skincopy(101 + 80, 66 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 2: Skincopy(114 + 80, 91 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 3: Skincopy(127 + 80, 66 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 4: Skincopy(140 + 80, 91 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 5: Skincopy(166 + 80, 91 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 6: Skincopy(179 + 80, 66 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 7: Skincopy(191 + 80, 91 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 8: Skincopy(204 + 80, 66 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 9: Skincopy(217 + 80, 91 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 10: Skincopy(230 + 80, 66 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 11: Skincopy(243 + 80, 91 + (Cur_Height - 140), 301, 119, 13, 13); break;
                case 12: Skincopy(269 + 80, 91 + (Cur_Height - 140), 301, 119, 13, 13); break;
            }
        }

        // Light pause/note led
        if(gode == 0 || gode == 10)
        {
            if(tb303[Unit].flag[tb303[Unit].selectedpattern][editsteps[Unit][tb303[Unit].selectedpattern]].pause)
            {
                Skincopy(402, (Cur_Height - 79), 138, 119, 3, 3);
                Skincopy(439, (Cur_Height - 79), 143, 119, 3, 3);
            }
            else
            {
                Skincopy(402, (Cur_Height - 79), 143, 119, 3, 3);
                Skincopy(439, (Cur_Height - 79), 138, 119, 3, 3);
            }
        }

        // Light slide/off led
        if(gode == 0 || gode == 11)
        {
            if(tb303[Unit].flag[tb303[Unit].selectedpattern][editsteps[Unit][tb303[Unit].selectedpattern]].slide_flag)
            {
                Skincopy(456, (Cur_Height - 57), 138, 119, 3, 3);
            }
            else
            {
                Skincopy(456, (Cur_Height - 57), 143, 119, 3, 3);
            }
        }

        // Light accent/off led
        if(gode == 0 || gode == 12)
        {
            if(tb303[Unit].flag[tb303[Unit].selectedpattern][editsteps[Unit][tb303[Unit].selectedpattern]].accent_flag)
            {
                Skincopy(431, (Cur_Height - 57), 138, 119, 3, 3);
            }
            else
            {
                Skincopy(431, (Cur_Height - 57), 143, 119, 3, 3);
            }
        }

        // Transpose up flag
        if(gode == 0 || gode == 13)
        {
            if(tb303[Unit].flag[tb303[Unit].selectedpattern][editsteps[Unit][tb303[Unit].selectedpattern]].transposeup_flag)
            {
                Skincopy(406, (Cur_Height - 57), 138, 119, 3, 3);
            }
            else
            {
                Skincopy(406, (Cur_Height - 57), 143, 119, 3, 3);
            }
        }

        // Transpose down flag
        if(gode == 0 || gode == 14)
        {
            if(tb303[Unit].flag[tb303[Unit].selectedpattern][editsteps[Unit][tb303[Unit].selectedpattern]].transposedown_flag)
            {
                Skincopy(381, (Cur_Height - 57), 138, 119, 3, 3);
            }
            else
            {
                Skincopy(381, (Cur_Height - 57), 143, 119, 3, 3);
            }
        }

        // Volume
        if(gode == 0 || gode == 15)
        {
            // volume background
            Skincopy(529, (Cur_Height - 115), 449, 25, 19, 88);
            int tb303v = (int) (tb303engine[Unit].tbVolume * 72.0f);
            // Volume slider
            Skincopy(531, (Cur_Height - 42) - tb303v, 0, 116, 13, 11);
        }

        if(gode == 0 || gode == 18)
        {
            sprintf(tcp, "%s_", tb303[Unit].pattern_name[tb303[Unit].selectedpattern]);

            if(snamesel == INPUT_303_PATTERN)
            {
                Gui_Draw_Button_Box(600, (Cur_Height - 120), 164, 16, tcp, BUTTON_PUSHED | BUTTON_INPUT);
            }
            else
            {
                Gui_Draw_Button_Box(600, (Cur_Height - 120), 164, 16, tb303[Unit].pattern_name[tb303[Unit].selectedpattern], BUTTON_NORMAL | BUTTON_INPUT);
            }
        }

        if(gode == 0 || gode == 19)
        {
            Gui_Draw_Arrows_Number_Box2(670, (Cur_Height - 42), tb303[Unit].scale, BUTTON_NORMAL | BUTTON_RIGHT_MOUSE | BUTTON_TEXT_CENTERED);
        }

    }
}
示例#3
0
int ScaleKnob(int wMin, int wMax)
{
  return MultDiv(knob(), wMax-wMin, 255) + wMin;
}
示例#4
0
// Displays a tuning parameter on the LCD
void ProcessMenu()
{
	motor.stop_all();
	int debounceTime = 200;
	int knobValue = knob(VALUE_ADJUST_KNOB) / 4;
	LCD.clear(); LCD.setCursor(0,1);
	LCD.print("Set to "); LCD.print(knobValue); LCD.print("?");
	LCD.home();

	int menuItem = knob(MENU_ADJUST_KNOB) / 200; // Divides by 256 to reduce possible values
	switch (menuItem)
	{
	case SPEED:
		LCD.print("Speed: ");
		LCD.print(speed);
		if (!StopButton(debounceTime)) break;
		speed = knobValue * 4;
		EEPROM.write(SPEED, speed / 4); // divide by four to prevent overflow (EEPROM max is 255)
		break;
	case PROPORTIONAL_GAIN:
		LCD.print("P Gain: ");
		LCD.print(proportionalGain);
		if (!StopButton(debounceTime)) break;
		proportionalGain = knobValue;
		EEPROM.write(PROPORTIONAL_GAIN, proportionalGain);
		break;
	case DERIVATIVE_GAIN:
		LCD.print("D Gain: ");
		LCD.print(derivativeGain);
		if (!StopButton(debounceTime)) break;
		derivativeGain = knobValue;
		EEPROM.write(DERIVATIVE_GAIN, derivativeGain);
		break;
	case THRESHOLD:
		LCD.print("TH: ");
		LCD.print((int)threshold);
		LCD.print(" ");
		LCD.print(left);
		LCD.print(" ");
		LCD.print(right);
		if (!StopButton(debounceTime)) break;
		threshold = knobValue * 2;
		EEPROM.write(THRESHOLD, threshold / 2);
		break;
	case PERPENDICULAR:
		LCD.print("PERP: ");
		LCD.print((int)perpendicular);
		if (!StopButton(debounceTime)) break;
		perpendicular = knobValue;
		EEPROM.write(PERPENDICULAR, perpendicular);
		break;
	default:
		LCD.print("PERP: ");
		LCD.print((int)perpendicular);
		if (!StopButton(debounceTime)) break;
		perpendicular = knobValue;
		EEPROM.write(PERPENDICULAR, perpendicular);
		break;
	}
	delay(30); // Pauses to prevent screen flicker
}
示例#5
0
// Displays a tuning parameter on the LCD
void ProcessMenu()
{
	motor.stop_all();
	int debounceTime = 200;
	int knobValue = knob(VALUE_ADJUST_KNOB);
	LCD.clear(); LCD.setCursor(0,1);
	LCD.print("Set to "); LCD.print(knobValue); LCD.print("?");
	LCD.home();

	int menuItem = knob(MENU_ADJUST_KNOB) / 100; // Divides by 1 to reduce possible values to something like 10
	switch (menuItem)
	{
		case SPEED:
		LCD.print("Speed: ");
		LCD.print(speed);
		if (!StopButton(debounceTime)) break;
		speed = knobValue ;
		EEPROM.write(SPEED, speed / 4); // divide by four to prevent overflow (EEPROM max is 255)
		break;
		case PROPORTIONAL_GAIN:
		LCD.print("P Gain: ");
		LCD.print(proportionalGain);
		if (!StopButton(debounceTime)) break;
		proportionalGain = knobValue;
		EEPROM.write(PROPORTIONAL_GAIN, proportionalGain/4);
		break;
		case DERIVATIVE_GAIN:
		LCD.print("D Gain: ");
		LCD.print(derivativeGain);
		if (!StopButton(debounceTime)) break;
		derivativeGain = knobValue;
		EEPROM.write(DERIVATIVE_GAIN, derivativeGain/4);
		break;
		case INTEGRAL_GAIN:
		LCD.print("I Gain: ");
		LCD.print(integralGain);
		if (!StopButton(debounceTime)) break;
		integralGain = knobValue;
		EEPROM.write(INTEGRAL_GAIN, integralGain/4);
		break;
		case THRESHOLD_LEFT:
		LCD.print("TH L: ");
		LCD.print((int)thresholdLeft);
		LCD.print(" ");
		LCD.print(left);
		if (!StopButton(debounceTime)) break;
		thresholdLeft = knobValue;
		EEPROM.write(THRESHOLD_LEFT, thresholdLeft / 4);
		break;
		case THRESHOLD_RIGHT:
		LCD.print("TH R: ");
		LCD.print((int)thresholdRight);
		LCD.print(" ");
		LCD.print(right);
		if (!StopButton(debounceTime)) break;
		thresholdRight = knobValue;
		EEPROM.write(THRESHOLD_RIGHT, thresholdRight / 4);
		break;
		case PERPENDICULAR:
		LCD.print("PERP: ");
		LCD.print((int)perpendicular);
		if (!StopButton(debounceTime)) break;
		perpendicular = knobValue;
		EEPROM.write(PERPENDICULAR, perpendicular /4 );
		break;
		case TURN_COMPENSATION:
		LCD.print("COMP: ");
		LCD.print((int)turnCompensationGain);
		if (!StopButton(debounceTime)) break;
		turnCompensationGain = knobValue;
		EEPROM.write(TURN_COMPENSATION, turnCompensationGain /4 );
		break;
		default:
		LCD.print("PERP: ");
		LCD.print((int)perpendicular);
		if (!StopButton(debounceTime)) break;
		perpendicular = knobValue;
		EEPROM.write(PERPENDICULAR, perpendicular / 4);
		break;
	}
	delay(30); // Pauses to prevent screen flicker
}
示例#6
0
void loop()
{
  RCServo1.write(angle_neutral);
  collector_switchState = LOW;


    if (timeTicker == 50) {
        timeTicker = 0; 

      if (startbutton() && !startButtonState) {
                if (menuState == 3) {
                    menuState = 1;
                } else {
                    menuState++;
                }
                editable = false;
                startButtonState = true;
                delay(500);
            } else if (stopbutton() && !stopButtonState) {
                editable = true;
                stopButtonState = true;
            } else {
                stopButtonState = false;
                startButtonState = false;
            }
            LCD.clear();    
    

            // Menu System
                // 1:   

            switch (menuState) {    

                case 1:
                    LCD.print("Rest: ");
                    userSet = (int)(knob(6) * 180.0/1024.0);
                    if (userSet != angle_neutral && editable){
                        angle_neutral = userSet;
                    }
                    LCD.print(angle_neutral, DEC);  

                    LCD.setCursor(0,1); 

                    LCD.print("Collect?: Y/N  ");
                    userSet = (int)(knob(7) * 2.0/1024.0);
                    if(userSet != collect_status && editable){
                        collect_status = userSet;
                    }
                    LCD.print(collect_status, DEC); 

                    break;
              
                case 2:
                    LCD.print("Min: ");
                    userSet = (int)(knob(6) * 180.0/1024.0);
                    if(userSet != angle_min && editable){
                        angle_min = userSet;
                    }
                    LCD.print(angle_min, DEC);  

                    LCD.setCursor(0,1); 

                    LCD.print("Max: ");
                    userSet = (int)(knob(7) * 180.0/1024.0);
                    if(userSet != angle_max && editable){
                        angle_max = userSet;
                    }
                    LCD.print(angle_max, DEC);  

                    break;

                case 3:
                    LCD.print("TestRange: ");
                    userSet = 1.5*(int)(knob(6) * 180.0/1024.0);
                    if(userSet != angle_neutral && editable){
                        if (userSet >= 180){
                            angle_neutral = 180;
                        } else{
                            angle_neutral = userSet;
                        }
                    }
                    LCD.print(angle_neutral, DEC);

                    break;
                }   

    }


    if(collect_status == 1){
        collector_switchState = digitalRead(COLLECTOR_SWITCHPIN);   

        if(collector_switchState){
            RCServo1.write(angle_min);
            delay(200);
            RCServo0.write(angle_max);
            delay(200);
            pusher_activate();
            RCServo1.write(angle_neutral);
            collector_switchState = false;
        }   

    }

    timeTicker++;

}