Miguel_Corza
Published © CC BY

Sine Wave generator

trigonometry, arduino, interesting, and funny!! can you do it? ⚡

IntermediateShowcase (no instructions)2 hours646
Sine Wave generator

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Adafruit OLED 128 x 64
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
9V battery (generic)
9V battery (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Compontents

Schematics

Schematics

Code

Code

Arduino
In this code, the degrees increase until they reach 360 and then return to 0, restarting the summation, the grades increments of 5. The degrees are converted to radians and multiplying them by 100, creating intervals of a size that can be visualized on the screen. Bassically, in line 26 the stored values of each of the 127 positions are printed pixel by pixel, and the updating process continues.
#Miguel Angel Perez Corza 7/25/23 => Hackster.io / Miguel_Corza

#define WIDTH 128
#define HEIGHT 64

int x[128];
int y[128];
Adafruit_SSD1306 display(WIDTH, HEIGHT, &Wire, -1);
int degree = 0;
void setup()
{
  pinMode(11, OUTPUT);
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

}
void loop()
{
  display.clearDisplay();
  display.setTextColor(WHITE);
  degree = degree + 5;
    float radian = degree*PI/180;
   float seno = sin(radian)*100;
   int val = map(seno,-100,100,0,54);
   x[127] = val;

for(int c = 127; c>=0; c--){
  display.drawPixel(c, x[c], WHITE);
  
  int led = map(x[0], 54,0, 0,255);
  
  analogWrite(11, led);
  y[c-1]=x[c];
}
 for(int d=127;d>=0;d--){
    x[d]=y[d]; 
  } 
  display.drawLine(0,32,128, 32, WHITE);
  display.display();

   
  if(degree >=360){
    degree = 0;
  }
}

Credits

Miguel_Corza

Miguel_Corza

2 projects • 3 followers
I am currently a student of electronics and a future engineer. I enjoy creating and inventing new electronic projects.

Comments