Int self [254]; // Sine value table.
Int outputArray [8] = {0, 1, 2, 3, 4, 5, 6, 7}; // Table for Output Pin (D0-D7)
Int ledArray [4] = {8, 9, 10, 11}; // Led-Panel for Output Pin of Signal LEDs
Int Signal = 0; // Signal selection variable.
Int buttonPin = 12; // Pin for the toggle button.
Int buttonState = 0; // Button status variable.
Int PotFunc = 0; // Potentiometer pin for signal frequency adjustment.
Int = 0; // Variable for the value of the frequency potentiometer.
Int PotGain = 1; // Potentiometer pin for signal width adjustment.
Int val1 = 0; // Variable for the value of the amplitude potentiometer.
// Plate setting function.
Void setup ()
{
 // Define pin 0 to 7 as outputs (digital signal).
 For (int i = 0; i <8; i ++)
 PinMode (outputArray [i], OUTPUT);
 // Define pin 8 to 11 as outputs (Display LED).
 For (int i = 0; i <4; i ++)
 PinMode (ledArray [i], OUTPUT);
 // Set pin 12 as input (button).
 PinMode (buttonPin, INPUT);
 Float x; // auxiliary variable.
 Float y; // auxiliary variable.
 // Fill the sine table with 256 sine values ​​from 0 to 2 (without negative values).
 For (int i = 0; i <255; i ++)
 {
 X = float (i);
 Y = sin ((x / 255) * 2 * PI);
 Sine [i] = int (y * 127) + 127;
 }
}
// Function that controls the status of the toggle button.
Int statecheck () {
// If the Signal variable is greater than 4 (4 signals) then it is reset.
 If (Signal> 4)
 Signal = 0;
/ * Assign a value from the function that reads the state of the button to the button state variable * /
 ButtonState = digitalRead (buttonPin);
 // If the button is pressed (LOW mode)
 If (buttonState == LOW) {
 // Increases the variable to go to the next signal.
 Signal ++;
 // Wait time to press the button.
 Delay (300);
 }
 Return Signal;
}
// Function that takes the value of an LED and lights it after extinguishing all the rest.
Void ActiveLed (int Led) {
 Led--;
// Turns off all LEDs.
 For (int i = 0; i <4; i ++)
 DigitalWrite (ledArray [i], LOW);
 If (Led <4)
 DigitalWrite (ledArray [Led], HIGH); // Only lights the led set in the function
}
// Function that runs the main program continuously.
Void loop ()
{
 / * Initially no signal is working and none of the LEDs are lit. The state status of the button with statecheck () * /
 Signal = statecheck ();
 Val1 = analogRead (PotGain); / * Reading the value of the amplitude potentiometer and yield value in the variable val1. * /
 Val1 = map (val1,0,1023,1,5); // assign values ​​from range 0-1023 to 1-5.
 Val = analogRead (PotFunc); Continuous frequency potentiometer control.
 Val = map (wave, 0, 1023, 0, 20); // assign potentiometer values ​​in the range 0 to 20.
 // If the button is pressed, the value of the Signal increases and it enters the case
 Switch (Signal) {
 Case 1: / * If the Signal variable gets the value 1 then the following code is output that triangle output. * /
 ActiveLed (Signal) // is constantly checked if the button is pressed to turn on another LED.
 For (int i = 0; i <255; i ++) {// anode loop.
 DelayMicroseconds (wave); Frequency is defined by the delay.
 Signal = statecheck (); // constantly checks whether the button was pressed to change the signal.
 If (Signal! = 1) break; // if the Signal value changes then the program comes out of Loop.
 PORTD = i / val1; / * Output values ​​in the PORTD register. It is set to the potentiometer value so that the amplitude of my signal decreases or increases accordingly * /
 }
 For (int i = 255; i> 0; i--) {// cathode loop.
 Val = analogRead (PotFunc); Continuous frequency potentiometer control.
 Val = map (wave, 0, 1023, 0, 20); // assign potentiometer values ​​in the range 0 to 20.
 DelayMicroseconds (wave); Frequency is defined by the delay.
 Signal = statecheck (); // constantly checks whether the button has been pressed to change the signal.
 If (Signal! = 1) break; // if the Signal value changes then the program comes out of Loop.
 PORTD = i / val1; / * Output values ​​in the PORTD register. It is set to the potentiometer value so that the amplitude of my signal decreases or increases accordingly * /
 }
 Break;
 Case 2: / * In the case that the Signal variable gets the value 2 then the following code is output that outputs the sine signal. * /
 ActiveLed (Signal)
 For (int i = 0; i <254; i ++) {
 DelayMicroseconds (wave);
 Signal = statecheck ();
 If (Signal! = 2) break;
 PORTD = sine [i] / val1; / * Output values ​​of the sine value table in the PORTD register * /
 }
 Break;
 Case 3: / * Square mark. The loop is the same as the previous one except that the output here is 0 for a period and maximum (5V) for the next one and this is repeated until the signal switch is pressed. * /
 ActiveLed (Signal)
 For (int i = 0; i <255; i ++) {
 If (i <128) {
 Signal = statecheck ();
 If (Signal! = 3) break;
 DelayMicroseconds (wave);
 PORTD = 255 / val1;
 }
 Else
 {
 Signal = statecheck ();
 If (Signal! = 3) break;
 DelayMicroseconds (wave);
 PORTD = 0;
}
  }
  Break;
  Case 4: / * Sawn signal. The logic is repeated once again except that the saw signal increases to maximum voltage and then drops sharply to 0. * /
  ActiveLed (Signal)
  For (int i = 0; i <255; i ++) {
  If (Signal! = 4) break;
  Signal = statecheck ();
  DelayMicroseconds (wave);
  PORTD = i / val1;
  }
  Break;
  Default: / * State in which the Signal variable has the value of 0. No Led is lit and the output is 0 * /
  ActiveLed (Signal)
  PORTD = 0;
  Break;
  }
}



















