ESP32 Code zur Laser-Steuerung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

63 Zeilen
2.0KB

  1. /* Hello World Example
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/task.h"
  10. #include "esp_system.h"
  11. #include "esp_spi_flash.h"
  12. #include "driver/ledc.h"
  13. void app_main()
  14. {
  15. printf("Hello world!\n");
  16. ledc_timer_config_t timer_conf;
  17. timer_conf.duty_resolution = LEDC_TIMER_15_BIT;
  18. timer_conf.freq_hz = 50;
  19. timer_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
  20. timer_conf.timer_num = LEDC_TIMER_0;
  21. ledc_timer_config(&timer_conf);
  22. ledc_channel_config_t ledc_conf;
  23. ledc_conf.channel = LEDC_CHANNEL_0;
  24. ledc_conf.duty = 3276; //800; //3276; //1638; // to 3276
  25. ledc_conf.gpio_num = 15;
  26. ledc_conf.intr_type = LEDC_INTR_DISABLE;
  27. ledc_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
  28. ledc_conf.timer_sel = LEDC_TIMER_0;
  29. ledc_channel_config(&ledc_conf);
  30. /* Print chip information */
  31. esp_chip_info_t chip_info;
  32. esp_chip_info(&chip_info);
  33. printf("This is ESP32 chip with %d CPU cores, WiFi%s%s, ",
  34. chip_info.cores,
  35. (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
  36. (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
  37. printf("silicon revision %d, ", chip_info.revision);
  38. printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
  39. (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
  40. for (int i = 10; i >= 0; i--) {
  41. printf("Restarting in %d seconds...\n", i);
  42. vTaskDelay(1000 / portTICK_PERIOD_MS);
  43. if(ledc_conf.duty > 1000) {
  44. ledc_conf.duty = 800;
  45. } else {
  46. ledc_conf.duty = 3276;
  47. }
  48. ledc_channel_config(&ledc_conf);
  49. }
  50. printf("Restarting now.\n");
  51. fflush(stdout);
  52. esp_restart();
  53. }