我正在显示一本书中的一些代码,并尝试按章节进行组织。第2-7章已正确突出显示并设置了所需的样式。如果我允许我尝试在手风琴中添加制表符的第2章,它将违反内容大小限制。第1章是我试图从其他文件(如其他章节)中加载要突出显示的代码,并将其显示在选项卡中,但是如果不中断选项卡的工作,就无法突出显示代码。我是新手,所以这绝对不是最好的方式。谢谢您的帮助和建议。
由于我从其他文件中获取了手风琴页面,所以这看起来与我所看到的不完全相同。再次谢谢你。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript">
$("#tabs2").tabs();
$("#accordion").accordion({autoHeight:false,collapsible:true,"activate":false,heightStyle: "content",navigation: true});
//$("#tabs").tabs();
$.post("Blink.ino",function(postresult) {
$("#pan1").append(postresult);
$("#pan1").each(function (i, e) {
hljs.highlightBlock(e);
});
});
$.post("Ultimate_Machine.ino",function(postresult) {
$("#pan1-2").append(postresult);
$("#pan1-2").each(function (i, e) {
hljs.highlightBlock(e);
});
});
$.post("Twitter_Pet.ino",function(postresult) {
$("#pan3").append(postresult);
$("#pan3").each(function (i, e) {
hljs.highlightBlock(e);
});
});
$.post("Crystal_Ball.ino",function(postresult) {
$("#pan4").append(postresult);
$("#pan4").each(function (i, e) {
hljs.highlightBlock(e);
});
});
$.post("tardis.txt",function(postresult) {
$("#pan5").append(postresult);
$("#pan5").each(function (i, e) {
hljs.highlightBlock(e);
});
});
$.post("Train.ino",function(postresult) {
$("#pan6").append(postresult);
$("#pan6").each(function (i, e) {
hljs.highlightBlock(e);
});
});
$.post("tardis.txt",function(postresult) {
$("#pan7").append(postresult);
$("#pan7").each(function (i, e) {
hljs.highlightBlock(e);
});
});
</script>
<!-- Highlight.js -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/styles/solarized-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet">
<style type="text/css">
#accordion .ui-accordion-content {
max-height: 200px;
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h3>Arduino-LEGO-Projects-Jon-Lazar</h3>
<img src="./../SiteMaterial/books/LegoArduino/cover.jpg">
<img src="./../SiteMaterial/books/LegoArduino/android.png" />
<div id="accordion">
<!--
<h3><a href="#">Chapter 1</a></h3>
<div id="tabs">
<ul>
<li><pre><code class="arduino" id="pan1"><a href="Blink.ino"></code></pre>Blink</a></li>
<li><a href="Ultimate_Machine.ino">Ultimate Machine</a></li>
</ul>
</div>
// If Chapter 1&2 commented out it looks ideal
<h3><a href="#">Chapter 2</a></h3>
<div>
<div id="tabs2">
<ul>
<li><a href="#tab-1">Android</a></li>
<li><a href="#tab-2">One_Ultrasonics_With_Lights.ino</a></li>
<li><a href="#tab-3">Three_Ultrasonics_With_Lights.ino</a></li>
</ul>
<div id="tab-1">
<pre><code class="arduino">
// include the library for hobby servos
#include <Servo.h>
// DC hobby servo
Servo servo1;
// sets the constants for each of the sensor signal pins:
const int pingPin[] = {2, 3, 4};
// sets the increment counter for each sensor:
int counter = 0;
// sets the speed of the servo movement
int spd = 10;
// sets the left, right, and center positions of the servo
int left = 10;
int right = 170;
int center = (right - left) / 2;
// sets the variable to keep track of the servo angle
int angle = center;
void setup() {
// initialize serial communication:
Serial.begin(9600);
// turn on servo and move to center
servo1.attach(9);
servo1.write(center);
}
void loop() {
// establish variables for duration of the ping,
// and the distance result in inches:
long duration, inches;
// resets counter if we run out of sensors
if (counter == 3) counter = 0;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin[counter], OUTPUT);
digitalWrite(pingPin[counter], LOW);
delayMicroseconds(2);
digitalWrite(pingPin[counter], HIGH);
delayMicroseconds(5);
digitalWrite(pingPin[counter], LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin[counter], INPUT);
duration = pulseIn(pingPin[counter], HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
// moves the servo to the left if left sensor is triggered
if (inches < 6 && counter == 0) {
if (angle != left) {
for (int i=angle; i>left; i--) {
servo1.write(i);
delay(spd);
}
angle = left;
}
// moves to the center if center sensor is triggered
} else if (inches < 6 && counter == 1) {
// moves from left to center
if (angle < center) {
for (int i=angle; i<center; i++) {
servo1.write(i);
delay(spd);
}
// or moves from right to center
} else {
for (int i=angle; i>center; i--) {
servo1.write(i);
delay(spd);
}
}
angle = center;
// moves to the right if right sensor is triggered
} else if (inches < 6 && counter == 2) {
if (angle != right) {
for (int i=angle; i<right; i++) {
servo1.write(i);
delay(spd);
}
angle = right;
}
// otherwise hold steady at the current position
} else {
servo1.write(angle);
}
// send the value in inches to the Serial Monitor for each sensor
Serial.print("Sensor ");
Serial.print(counter);
Serial.print(": ");
Serial.print(inches);
Serial.println(" inches");
// increment counter for the next loop
counter++;
// short delay before starting over again
delay(100);
}
long microsecondsToInches(long microseconds) {
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
</code></pre>
</div>
<div id="tab-2">
<pre><code class="arduino">
// sets the constants for the sensor and led signal pins:
const int pingPin = 2;
const int led = 10;
void setup() {
// initialize serial communication:
Serial.begin(9600);
// sets the LED pin to an output mode
pinMode(led, OUTPUT);
}
void loop() {
// establish variables for duration of the ping,
// and the distance result in inches:
long duration, inches;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
// turn on the led if object is within six inches
if (inches < 6) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
// send the value in inches to the Serial Monitor
Serial.print(inches);
Serial.println(" inches");
// short delay before starting over again
delay(100);
}
long microsecondsToInches(long microseconds) {
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
</code></pre>
</div>
<div id="tab-3">
<pre><code class="arduino">
// sets the constants for each of the sensor and led signal pins:
const int pingPin[] = {2, 3, 4};
const int led[] = {10, 11, 12};
// sets the increment counter for each sensor:
int counter = 0;
void setup() {
// initialize serial communication:
Serial.begin(9600);
// sets each LED pin to an output mode
for (int i=0; i<3; i++) pinMode(led[i], OUTPUT);
}
void loop() {
// establish variables for duration of the ping,
// and the distance result in inches:
long duration, inches;
// resets counter if we run out of sensors
if (counter == 3) counter = 0;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin[counter], OUTPUT);
digitalWrite(pingPin[counter], LOW);
delayMicroseconds(2);
digitalWrite(pingPin[counter], HIGH);
delayMicroseconds(5);
digitalWrite(pingPin[counter], LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin[counter], INPUT);
duration = pulseIn(pingPin[counter], HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
// turn on the led if object is within six inches
if (inches < 6) {
digitalWrite(led[counter], HIGH);
} else {
digitalWrite(led[counter], LOW);
}
// send the value in inches to the Serial Monitor for each sensor
Serial.print("Sensor ");
Serial.print(counter);
Serial.print(": ");
Serial.print(inches);
Serial.println(" inches");
// increment counter for the next loop
counter++;
// short delay before starting over again
delay(100);
}
long microsecondsToInches(long microseconds) {
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
</code></pre>
</div>
</div>
</div
-->
<h3><a href="#">Chapter 3</a></h3>
<div>
<pre><code class="arduino" id="pan3"></code></pre>
</div>
<h3><a href="#">Chapter 4</a></h3>
<div>
<pre><code class="arduino" id="pan4"></code></pre>
</div>
<h3><a href="#">Chapter 5</a></h3>
<div>
<pre><code class="arduino" id="pan5"></code></pre>
</div>
<h3><a href="#">Chapter 6</a></h3>
<div>
<pre><code class="arduino" id="pan6"></code></pre>
</div>
<h3><a href="#">Chapter 7</a></h3>
<div>
<pre><code class="Arduino">
#include <AFMotor.h>
// Connect a stepper motor with 48 steps per revolution (7.5 degree)
// to motor port #1 (M1 and M2)
AF_Stepper motor(48, 1);
int photocellPin = A0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the sensor divider
int threshold = 200; // the amount of light required to activate the motor
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
motor.setSpeed(50); // 50 rpm
}
void loop() {
photocellReading = analogRead(photocellPin);
Serial.print("Photocell reading = ");
Serial.println(photocellReading); // the raw analog reading
if (photocellReading > threshold) {
motor.step(100, FORWARD, INTERLEAVE);
}
delay(100);
}
</code></pre>
</div>
</div>
</body>
</html>