Advertisement
Guest User

Untitled

a guest
May 19th, 2025
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.29 KB | Source Code | 0 0
  1. // For Arduino R4 Minima with L298N driver
  2.  
  3. const int in1 = A0;  // Top array control 1
  4. const int in2 = A1;  // Top array control 2
  5. const int in3 = A2;  // Bottom array control 1
  6. const int in4 = A3;  // Bottom array control 2
  7.  
  8. // Adjusted delay for 40 kHz
  9. int delayTime = 8.6;  // 8.4 to 8.7  microseconds should get closer to 40 kHz
  10.  
  11. void setup() {
  12.   // Set control pins as outputs
  13.   pinMode(in1, OUTPUT);
  14.   pinMode(in2, OUTPUT);
  15.   pinMode(in3, OUTPUT);
  16.   pinMode(in4, OUTPUT);
  17.  
  18.   // Initialize all pins to LOW
  19.   digitalWrite(in1, LOW);
  20.   digitalWrite(in2, LOW);
  21.   digitalWrite(in3, LOW);
  22.   digitalWrite(in4, LOW);
  23.  
  24.   Serial.begin(9600);
  25.   Serial.println("Acoustic Levitator - Tuned for 40kHz");
  26. }
  27.  
  28. void loop() {
  29.   // Phase 1: Top array active in one direction, bottom array in opposite direction
  30.   digitalWrite(in1, HIGH);  // Top array +
  31.   digitalWrite(in2, LOW);   // Top array -
  32.   digitalWrite(in3, LOW);   // Bottom array -
  33.   digitalWrite(in4, HIGH);  // Bottom array +
  34.   delayMicroseconds(delayTime);
  35.  
  36.   // Phase 2: Reverse the polarity on both arrays
  37.   digitalWrite(in1, LOW);   // Top array -
  38.   digitalWrite(in2, HIGH);  // Top array +
  39.   digitalWrite(in3, HIGH);  // Bottom array +
  40.   digitalWrite(in4, LOW);   // Bottom array -
  41.   delayMicroseconds(delayTime);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement