Diferencia entre revisiones de «Tocadiscos caja de ritmos»

De fabwiki
Ir a la navegación Ir a la búsqueda
Sin resumen de edición
Sin resumen de edición
Línea 100: Línea 100:
   delay(500);
   delay(500);
}
}
 
</pre>
=Codigo 3=
=Codigo 3=
<pre>
#define led 13   
#define led 13   
#define buzzer 11
#define buzzer 11
Línea 163: Línea 164:
   }
   }
}
}
</pre>

Revisión del 23:02 13 jul 2026


La idea es que el usuario quiere generar un ritmo. El usuario va a colocar imanes sobre la superficie de un disco giratorio. Las posiciones de los imanes representarán los tiempos de los sonidos de la caja de ritmo. Los imanes van a moverse. Sensores estacionarios de campos magnéticos van a detectar cuando los imanes pasan por el sensor.

Motor original

1290 rpm

84.7 cm de cinturón de goma

Motor Paso a Paso

Sensores Hall (para detectar campos magnéticos)

Videos

Codigo 1


#define led 13  
#define buzzer 11
#define analogPin A0

uint16_t analogVal;

void setup () {
  pinMode (led, OUTPUT);
  pinMode (buzzer, OUTPUT);
  Serial.begin(9600);
}

void loop () {
  analogVal = analogRead(analogPin);
  analogVal -= 640;
  

  Serial.print("0, "); Serial.print("300, "); 
  Serial.println(analogVal);
  if (analogVal > 50) {
    digitalWrite(led, HIGH);
    digitalWrite(buzzer, HIGH);
  }
  else {
    digitalWrite(led, LOW);
    digitalWrite(buzzer, LOW);
  }
  delayMicroseconds(1000);
}

Codigo 2

#define led 13  
#define buzzer 11
#define hall0 A0
#define hall1 A1

uint16_t hall0val;
uint16_t hall1val;

void setup () {
  pinMode (led, OUTPUT);
  pinMode (buzzer, OUTPUT);
  Serial.begin(9600);
}

void loop () {
  hall0val = analogRead(hall0);
  hall0val -= 640;
  
  hall1val = analogRead(hall1);
  hall1val -= 640;

  //Serial.print("0, "); Serial.print("300, "); 
  Serial.print(hall0val);
  Serial.print(" ");
  Serial.println(hall1val);

  if (hall0val > 50 || hall1val > 50) {
    digitalWrite(led, HIGH);
    digitalWrite(buzzer, HIGH);
  }
  else {
    digitalWrite(led, LOW);
    digitalWrite(buzzer, LOW);
  }
 // delayMicroseconds(300000);
   delay(500);
}

Codigo 3

#define led 13  
#define buzzer 11
#define hall0 A0
#define hall1 A1

uint16_t hall0val;
uint16_t hall1val;

const int OUT0_PIN = 6;
const int OUT1_PIN = 13;
const int DURACION_MS = 50;
const int HALL_OFFSET = 640;
const int HALL_THRES = 50;

void setup () {
  pinMode (led, OUTPUT);
  pinMode (buzzer, OUTPUT);
  pinMode (OUT0, OUTPUT);
  pinMode (OUT1, OUTPUT);

  Serial.begin(9600);
}

bool out0_on = false;

void loop () {
  int out0_off_time = 0;
  int out1_off_time = 1;
  bool out0_on = false;
  bool out1_on = false;
  hall0val = analogRead(hall0) - HALL_OFFSET;
  
  hall1val = analogRead(hall1) - HALL_OFFSET;

  //Serial.print("0, "); Serial.print("300, "); 
  Serial.print(hall0val);
  Serial.print(" ");
  Serial.println(hall1val);

  if (millis() > out0_off_time && out0_on == true) {
    digitalWrite(OUT0, LOW);
    out0_on = false;
  }

  if (millis() > out1_off_time && out1_on == true) {
    digitalWrite(OUT1, LOW);
    out0_on = false;
  }

  if (hall0val > HALL_THRES) {
    digitalWrite(OUT0, HIGH);
    out0_off_time = millis() + DURACION_MS;
    out0_on = true;
  }
  
  if (hall1val > HALL_THRES) {
    digitalWrite(OUT1, HIGH);
    out1_off_time = millis() + DURACION_MS;
    out1_on = true;
  }
}