Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- html = """
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Robot Arm Controller</title>
- <link rel="stylesheet" href="/style.css">
- </head>
- <body>
- <div id="slider-cont">
- <div id="base-cont" class="container">
- <div id="base-title" class="title-text">Base Pivot</div>
- <div id="base-toggle" class="toggle-button"></div>
- <input id="base-slider" class="slider" type="range" min="0" max="180"
- value="90">
- <input type="text" id='base-value' class='value-text' maxlength="3">
- </div>
- <div id="pivot1-cont" class="container">
- <div id="pivot1-title" class="title-text">Pivot 1</div>
- <div id="pivot1-toggle" class="toggle-button"></div>
- <input id="pivot1-slider" class="slider" type="range" min="0" max="180"
- value="0">
- <input type="text" id='base-value' class='value-text' maxlength="3">
- </div>
- <div id="pivot2-cont" class="container">
- <div id="pivot2-title" class="title-text">Pivot 2</div>
- <div id="pivot2-toggle" class="toggle-button"></div>
- <input id="pivot2-slider" class="slider" type="range" min="0" max="180"
- value="180">
- <input type="text" id='base-value' class='value-text' maxlength="3">
- </div>
- <div id="grabber-cont" class="container">
- <div id="grabber-title" class="title-text">End Effector Pivot</div>
- <div id="grabber-toggle" class="toggle-button"></div>
- <input id="grabber-slider" class="slider" type="range" min="0" max="180"
- value="180">
- <input type="text" id='base-value' class='value-text' maxlength="3">
- </div>
- <div id="effector-cont" class="container">
- <div id="effector-title" class="title-text">End Effector</div>
- <div id="effector-close"> <span
- style="position: relative; bottom: 0.15vh;"></span></div>
- <div id="torque-toggle"> <span
- style="position: relative; bottom: 0.15vh;">HI</span></div>
- </div>
- <div id="program-cont" class="container">
- <div id="program-button"><span>Program Runner</span></div>
- </div>
- </div>
- </body>
- <script>
- const toggleButton = document.getElementsByClassName('toggle-button');
- const sliders = document.getElementsByClassName('slider');
- const valueText = document.getElementsByClassName('value-text');
- const containers = document.getElementsByClassName('container');
- const grabber = document.getElementById('effector-close');
- const effectorSpan = grabber.getElementsByTagName('span')
- const torque = document.getElementById('torque-toggle');
- const torqueSpan = torque.getElementsByTagName('span');
- const programButton = document.getElementById('program-button')
- let torqueSelection = 40
- let xhr = new XMLHttpRequest();
- for (let i = 0; i < containers.length - 2; i++) {
- toggleButton[i].addEventListener('click', function () {
- if (!toggleButton[i].classList.contains('toggled')) {
- toggleButton[i].style = 'background-color:#45f542';//Green
- toggleButton[i].classList.add('toggled');
- } else if (toggleButton[i].classList.contains('toggled')) {
- toggleButton[i].style = 'background-color:#f55142';//Red
- toggleButton[i].classList.remove('toggled');
- };
- });
- valueText[i].addEventListener('keydown', function (e) {
- if (e.keyCode == 13) {
- sliders[i].value = valueText[i].value
- setTimeout(() => {
- xhr.open("GET", `/slider${i}?` + sliders[i].value, true);
- xhr.send();
- console.log(sliders[i].value);
- }, 250);
- };
- });
- sliders[i].addEventListener('input', function () {
- valueText[i].value = sliders[i].value;
- console.log('UPDATE!')
- });
- sliders[i].addEventListener('change', function () {
- if (toggleButton[i].classList.contains('toggled')) {
- setTimeout(() => {
- xhr.open("GET", `/slider${i}?` + sliders[i].value, true);
- xhr.send();
- console.log(sliders[i].value);
- }, 250);
- };
- });
- };
- torque.addEventListener('click', function () {
- if (!torque.classList.contains('toggled')) {
- torque.classList.add('toggled');
- torqueSpan[0].innerHTML = 'LO'
- torqueSelection = 40
- } else if (torque.classList.contains('toggled')) {
- torque.classList.remove('toggled');
- torqueSpan[0].innerHTML = 'HI';
- torqueSelection = 50
- };
- });
- grabber.addEventListener('click', function () {
- if (!grabber.classList.contains('toggled')) {
- grabber.style = 'background-color:#45f542';//Green
- grabber.classList.add('toggled');
- effectorSpan[0].innerHTML = 'Opened'
- setTimeout(() => {
- xhr.open("GET", `/slider5?` + 0, true);
- xhr.send();
- }, 250);
- } else if (grabber.classList.contains('toggled')) {
- grabber.style = 'background-color:#f55142';//Red
- grabber.classList.remove('toggled');
- effectorSpan[0].innerHTML = 'Closed'
- setTimeout(() => {
- xhr.open("GET", `/slider5?` + torqueSelection, true);
- xhr.send();
- }, 250);
- };
- });
- let isToggled = false;
- programButton.addEventListener('click', function() {
- isToggled = !isToggled;
- if(isToggled == true) {
- programButton.style.backgroundColor = 'rgb(69, 245, 66)'
- xhr.open("GET", `/slider6?` + 1, true);
- xhr.send();
- } else {
- programButton.style.backgroundColor = '#f55142'
- xhr.open("GET", `/slider6?` + 0, true);
- xhr.send();
- }
- });
- </script>
- </html>
- """
- cssString = """
- @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;700&display=swap');
- #slider-cont {
- width: 20vw;
- height: 100%;
- margin-left: auto;
- margin-right: auto;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .container {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: center;
- width: 100%;
- flex-wrap: wrap;
- }
- .title-text {
- font-family: 'Poppins', sans-serif;
- font-size: 1.7vw;
- font-weight: 700;
- color: black;
- text-align: center;
- width: 100%;
- }
- .slider {
- -webkit-appearance: none;
- /* Override default CSS styles */
- appearance: none;
- width: 10vw;
- /* Full-width */
- height: 0.983vw;
- /* Specified height */
- background: #d3d3d3;
- /* Grey background */
- outline: none;
- /* Remove outline */
- opacity: 0.7;
- /* Set transparency (for mouse-over effects on hover) */
- -webkit-transition: .2s;
- /* 0.2 seconds transition on hover */
- transition: opacity .2s;
- border-radius: 25px;
- }
- .slider::-webkit-slider-thumb {
- appearance: none;
- -webkit-appearance: none;
- width: 0.781vw;
- height: 0.781vw;
- border-radius: 50%;
- background-color: black;
- border: none;
- }
- .slider::-moz-range-thumb {
- width: 1.302vw;
- height: 1.302vw;
- border-radius: 100%;
- background-color: black;
- border: none;
- }
- .toggle-button {
- width: 2.5vw;
- height: 2.5vw;
- background-color: #f55142;
- border-radius: 50%;
- position: relative;
- right: 1vw;
- }
- .value-text {
- width: 5vw;
- height: 2vw;
- background-color: #4b4b4b;
- border-radius: 1vw;
- font-family: 'Poppins', sans-serif;
- font-size: 1.5vw;
- font-weight: 700;
- color: white;
- text-align: center;
- border: none;
- position: relative;
- left: 1vw;
- }
- #effector-close {
- width: 7vw;
- height: 2vw;
- background-color: rgb(69, 245, 66);
- border-radius: 1vw;
- font-family: 'Poppins', sans-serif;
- font-size: 1.5vw;
- font-weight: 700;
- color: white;
- text-align: center;
- user-select: none;
- position: relative;
- right: 1.5vw;
- }
- #torque-toggle {
- width: 7vw;
- height: 2vw;
- background-color: #4b4b4b;
- border-radius: 1vw;
- font-family: 'Poppins', sans-serif;
- font-size: 1.5vw;
- font-weight: 700;
- color: white;
- text-align: center;
- user-select: none;
- position: relative;
- left: 1.5vw;
- }
- #program-button {
- width: 9vw;
- height: 4vw;
- border-radius: 4vw;
- background-color: #f55142;
- text-align: center;
- margin-top: 1.5vw;
- }
- #program-button:hover {
- background-color: #e64c3e;
- }
- #program-button:active {
- background-color: #b33b30;
- }
- #program-button > span {
- font-family: 'Poppins', sans-serif;
- font-size: 1.3vw;
- font-weight: 700;
- color: white;
- width: 100%;
- user-select: none;
- position: relative;
- top: 0.1vw;
- }
- @media only screen and (max-width: 600px) {
- #slider-cont {
- width: 100%;
- }
- .title-text {
- font-size: 4.7vw;
- }
- .toggle-button {
- width: 6.5vw;
- height: 6.5vw;
- position: relative;
- right: 3vw;
- }
- .slider {
- width: 50vw;
- height: 3.0vw;
- }
- .slider::-webkit-slider-thumb {
- width: 4.3vw;
- height: 4.3vw;
- }
- .slider::-moz-range-thumb {
- width: 4.3vw;
- height: 4.3vw;
- }
- .value-text {
- width: 11vw;
- height: 5vw;
- font-size: 4.5vw;
- border-radius: 2.3vw;
- position: relative;
- left: 3vw;
- }
- #effector-toggle {
- position: relative;
- right: 13.5vw;
- }
- #effector-close {
- width: 30vw;
- height: 6vw;
- border-radius: 5vw;
- font-size: 4.5vw;
- }
- #torque-toggle {
- width: 12vw;
- height: 6vw;
- font-size: 4.5vw;
- border-radius: 2.3vw;
- position: relative;
- left: 13.4vw;
- }
- #program-button {
- width: 30vw;
- height: 12vw;
- border-radius: 12vw;
- margin-top: 3vw;
- }
- #program-button > span {
- font-size: 3.6vw;
- font-weight: 700;
- position: relative;
- top: 0.4vw;
- }
- }
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement