Advertisement
ByRussX

Car Lights

Feb 7th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let isOn = false;
  2. let mode = false;
  3.  
  4. if (sensors.color1.light(LightIntensityMode.Ambient)) {
  5.     brick.setStatusLight(StatusLight.Off);
  6.     isOn = false;
  7. }
  8. else {
  9.     brick.setStatusLight(StatusLight.Orange);
  10.     isOn = true;
  11. }
  12.  
  13. brick.showString("Automatic", 1);
  14.  
  15. // Funciones para manejar las luces
  16.  
  17. function autoLights() {
  18.     if (sensors.color1.light(LightIntensityMode.Ambient)) {
  19.         brick.setStatusLight(StatusLight.Off);
  20.         isOn = false;
  21.  
  22.     }
  23.     else {
  24.         brick.setStatusLight(StatusLight.Orange);
  25.         isOn = true;
  26.     }
  27. }
  28.  
  29. function manualLights() {
  30.     if (brick.buttonEnter.isPressed()) {
  31.         while (brick.buttonEnter.isPressed())
  32.         { }
  33.         brick.setStatusLight((isOn) ? StatusLight.Off : StatusLight.Orange);
  34.         isOn = (isOn) ? false : true;
  35.  
  36.     }
  37. }
  38.  
  39. forever
  40.     (
  41.     function () {
  42.         while (true) {
  43.             if (brick.buttonDown.isPressed()) {
  44.                 while (brick.buttonEnter.isPressed())
  45.                 { }
  46.                 mode = (mode) ? false : true;
  47.                 brick.showString((mode) ? "Manual" : "Automatic", 1);
  48.             }
  49.  
  50.             if (mode) {
  51.                 manualLights();
  52.             }
  53.             else {
  54.                 autoLights();
  55.             }
  56.         }
  57.     }
  58.     )
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement